I’m trying to populate some meta data fields with text used as descriptions. This description text is used in headers etc elsewhere and sometimes I don’t want words to be separated across lines and so use .
e.g. description = "The shop closes in 12 mins"
{{ else if .Params.description }}
<meta
property="og:description"
content="{{ .Params.description | plainify }}"
/>
{{ end }}
results in
<meta
property="og:description"
content="The shop closes in 12&nbsp;mins"
/>
I’d rather it render to:
<meta
property="og:description"
content="The shop closes in 12 mins"
/>
Is this possible using something other than plainify?
Answering my own question, “yes”.
{{ else if .Params.description }}
<meta name="description" content="{{ .Params.description | plainify | htmlUnescape }}" />
{{ end }}
htmlUnescape is the key. I should have searched the repo first for the plainify code. I found the following file: hugo/transform.Unmarshal.md at 258884f44fc3ea6e4954936ddeb24e739eb8f58a · gohugoio/hugo · GitHub
But is the documentation correct stating “Plainify returns a copy of s with all HTML tags removed”?
is an HTML entity, not an HTML element.
Thanks - I’ve learned two things this evening!
The docs state for plainify “Strips any HTML and returns the plain text version of the provided string”, and I naively assumed that would include HTML character codes. Perhaps that should read “any HTML elements”?
It is now a verbatim copy of the source code description.
https://gohugo.io/functions/plainify/
And to clarify, this is an HTML element:
<div>foo</div>
These are HTML tags: