mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-03 16:51:47 +00:00
Add trim and replace template functions
This commit is contained in:
parent
32d15d91fc
commit
871e811339
2 changed files with 12 additions and 0 deletions
|
@ -292,6 +292,16 @@ Removes any trailing newline characters. Useful in a pipeline to remove newlines
|
|||
|
||||
e.g., `{{chomp "<p>Blockhead</p>\n"` → `"<p>Blockhead</p>"`
|
||||
|
||||
### trim
|
||||
Trim returns a slice of the string with all leading and trailing characters contained in cutset removed.
|
||||
|
||||
e.g. `{{ trim "++Batman--" "+-" }}` → "Batman"
|
||||
|
||||
### replace
|
||||
Replace all occurences of the search string with the replacement string.
|
||||
|
||||
e.g. `{{ replace "Batman and Robin" "Robin" "Catwoman" }}` → "Batman and Catwoman"
|
||||
|
||||
### highlight
|
||||
Take a string of code and a language, uses Pygments to return the syntax highlighted code in HTML. Used in the [highlight shortcode](/extras/highlighting).
|
||||
|
||||
|
|
|
@ -1237,6 +1237,8 @@ func init() {
|
|||
"relref": RelRef,
|
||||
"apply": Apply,
|
||||
"chomp": Chomp,
|
||||
"replace": func(a string, b string, c string) string { return strings.Replace(a, b, c, -1) },
|
||||
"trim": func(a string, b string) string { return strings.Trim(a, b) },
|
||||
}
|
||||
|
||||
chompRegexp = regexp.MustCompile("[\r\n]+$")
|
||||
|
|
Loading…
Reference in a new issue