I discovered some errors with my Atom feed template because an HTML encoded entity (’
) was not valid in XML. So I decided to put all my type="html
element contents into CDATA blocks, and wrote this partial (I will eventually escape instances of []>
) :
{{ printf "<![CDATA[%s]]>" . | safeHTML }}
It works great most of the time, for example:
<summary type="html">{{ partial "cdata.xml" .Title }}</summary>
Which properly outputs:
<summary type="html"><![CDATA[Hello there]]></summary >
Except when I use it in a <title>
element:
<title type="html">{{ partial "cdata.xml" .Title }}</title>
When the output is:
<title type="html"><![CDATA[Hello there]]></title>
Why does it escape the <
and >
? If I change it to titl
it works. What’s so special about title? What’s the proper way to work around this? For now I’ve circumvented it with a printf
:
{{ printf `<title type="html">%s</title>` (.Title | markdownify | partial "cdata.xml") | safeHTML }}
Which seems unfortunate TBH.