I think this is coming from html/template, not shortcodes. It’s smart enough to detect that you’re printing a variable in a <script> context, and therefore escapes it. It looks like the right way around this is to call template.JS but there’s no safeJS function available in template_funcs.go that would wrap this call.
Sounds like a good feature to add, unless there’s some way to convince html/template not to handle <script type="math/tex"> fields like it handles JavaScript.
@bep I tried with .Inner but it didn’t helped either. Calling the shortcode
<script type="math/tex" >{{ .Inner }}</script>
in my post with
{{% katex %}}S_n = a \times \frac{1-r^n}{1-r}{{% /katex %}}
doesn’t fix it. The output is still:
<p><script type="math/tex" >"S_n = a \\times \\frac{1-r^n}{1-r}"</script></p>.
@dimo414 I did a bit of research and found similar problems on Stackoverflow that required mostly a custom function/filter. This article shows pretty good, that the quotation is added to prevent XSS-attacks and other abuse.
There I would suggest to add a filter named saveJS to Hugo.
I’m having a similar problem. I’m trying to inject a variable into a script to drop markers on a map. Here’s a snippet of the javascript (it’s in a partial):
{{ range $.Site.Data.events }}
{{ if eq .status "current" }}
['{{ .city}} ', {{ .coordinates | safeHTML }}],
{{ end }}
{{ end }}
];
The problem is, the output then looks like this:
var markers = [
['Kiel', "47.609895, -122.330259"],
];
Google Maps requires the coordinates to NOT be in quotation marks. Suggestions?
That would definitely help! In our workflow, we’ll probably have to wait until 1.5 is released, since we use wercker to build the site, etc, so we can’t really use dev versions of hugo