mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-13 18:07:24 -04:00
Add htmlEscape
and htmlUnescape
template functions
These functions allow trivial escaping and unescaping of HTML entities, and make it far easier to compose other functions for the creation of parameterised URLs.
This commit is contained in:
parent
6640c52c82
commit
8d01874049
@ -448,6 +448,27 @@ e.g. `{{ "I :heart: Hugo" | emojify }}`
|
|||||||
Takes a string of code and a language, uses Pygments to return the syntax highlighted code in HTML.
|
Takes a string of code and a language, uses Pygments to return the syntax highlighted code in HTML.
|
||||||
Used in the [highlight shortcode](/extras/highlighting/).
|
Used in the [highlight shortcode](/extras/highlighting/).
|
||||||
|
|
||||||
|
### htmlEscape
|
||||||
|
HtmlEscape returns the given string with the critical reserved HTML codes escaped,
|
||||||
|
such that `&` becomes `&` and so on. It escapes only: `<`, `>`, `&`, `'` and `"`.
|
||||||
|
|
||||||
|
Bear in mind that, unless content is passed to `safeHTML`, output strings are escaped
|
||||||
|
usually by the processor anyway.
|
||||||
|
|
||||||
|
e.g.
|
||||||
|
`{{ htmlEscape "Hugo & Caddy > Wordpress & Apache" }} → "Hugo & Caddy > Wordpress & Apache"`
|
||||||
|
|
||||||
|
### htmlUnescape
|
||||||
|
HtmlUnescape returns the given string with html escape codes un-escaped. This
|
||||||
|
un-escapes more codes than `htmlEscape` escapes, including `#` codes and pre-UTF8
|
||||||
|
escapes for accented characters. It defers completely to the Go `html.UnescapeString`
|
||||||
|
function, so functionality is consistent with that codebase.
|
||||||
|
|
||||||
|
Remember to pass the output of this to `safeHTML` if fully unescaped characters
|
||||||
|
are desired, or the output will be escaped again as normal.
|
||||||
|
|
||||||
|
e.g.
|
||||||
|
`{{ htmlUnescape "Hugo & Caddy > Wordpress & Apache" }} → "Hugo & Caddy > Wordpress & Apache"`
|
||||||
|
|
||||||
### humanize
|
### humanize
|
||||||
Humanize returns the humanized version of an argument with the first letter capitalized.
|
Humanize returns the humanized version of an argument with the first letter capitalized.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user