I’m trying to define a short code to enable syntax highlighting via Google’s prettify.js:
<pre class="prettyprint linenums"><code class="language-{{ .Get 0 }}">{{ .Inner }}</code></pre>
Using it with Java code renders nicely. But for XML or HTML it’s missing the escaping of “<”, “>” etc. So I added a call to htmlEscape() to the short code:
<pre class="prettyprint linenums"><code class="language-{{ .Get 0 }}">{{ htmlEscape .Inner }}</code></pre>
But strangely this escapes the inner content twice. E.g. this contents in my Markdown file
{{< prettify xml >}}<some-xml>...</some-xml>{{< /prettify >}}
Will be rendered into
<pre class="prettyprint linenums"><code class="language-xml">
&lt;some-xml&gt;...&lt;/some-xml&gt;
</code></pre>
Instead of the desired
<pre class="prettyprint linenums"><code class="language-xml">
<some-xml>...</some-xml>
</code></pre>
I.e. the “&” character of an escape symbol such as “<” is escaped another time with “&”. What am I doing wrong here?