# Can't insert shortcode parameter without quotation marks

**URL:** <https://discourse.gohugo.io/t/cant-insert-shortcode-parameter-without-quotation-marks/1481>\
**Category:** support\
**Tags:** typesetting\
**Created:** [July 26, 2015, 4:09pm UTC](https://discourse.gohugo.io/t/cant-insert-shortcode-parameter-without-quotation-marks/1481 "2015-07-26T16:09:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![digitalcraftsman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/digitalcraftsman/32/4142_2.png) [@digitalcraftsman](https://discourse.gohugo.io/u/digitalcraftsman)\
**Post date:** [July 26, 2015, 4:09pm UTC](https://discourse.gohugo.io/t/cant-insert-shortcode-parameter-without-quotation-marks/1481/1 "2015-07-26T16:09:51Z")

</div>

To enable the rendering of equations I need to put the formula into a scripttag that uses `type="math/tex"` as attribute.

The shortcode is called with

`{{% equation "f(x) = \int \frac{2x^2+4x+6}{x-2}" %}}`

The shortcode looks like

```html
<script type="math/tex">{{ .Get 0 }}</script>

```

The output I get:

```html
<p>
<script type="math/tex">"f(x) = \\int \\frac{2x^2+4x+6}{x-2}"</script>
</p>

```

But the equation can’t be wrapped into quotation marks, otherwise it can’t be interpreted/rendered. If I include the expected output (without quotes)

```html
<script type="math/tex">S_n = a \times \frac{1-r^n}{1-r}</script>

```

into the shortcode everything works fine.

I already experimented with `replace`, `substring` and `printf "%s" .Get 0` but none of this approaches turned out to be successful.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [July 26, 2015, 5:37pm UTC](https://discourse.gohugo.io/t/cant-insert-shortcode-parameter-without-quotation-marks/1481/2 "2015-07-26T17:37:14Z")

</div>

A shortcode with `.Inner` content seems like a better fit for this.

---

<div class="post-metadata">

**Author:** ![dimo414](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/dimo414/32/564_2.png) [@dimo414](https://discourse.gohugo.io/u/dimo414)\
**Post date:** [July 26, 2015, 10:47pm UTC](https://discourse.gohugo.io/t/cant-insert-shortcode-parameter-without-quotation-marks/1481/3 "2015-07-26T22:47:32Z")

</div>

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`](http://golang.org/pkg/html/template/#JS) but there’s no `safeJS` function available in [`template_funcs.go`](https://github.com/spf13/hugo/blob/master/tpl/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.

---

<div class="post-metadata">

**Author:** ![digitalcraftsman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/digitalcraftsman/32/4142_2.png) [@digitalcraftsman](https://discourse.gohugo.io/u/digitalcraftsman)\
**Post date:** [July 29, 2015, 9:13am UTC](https://discourse.gohugo.io/t/cant-insert-shortcode-parameter-without-quotation-marks/1481/4 "2015-07-29T09:13:37Z")

</div>

@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](http://ejj.io/golang-htmltemplates/) 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.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [July 29, 2015, 10:15am UTC](https://discourse.gohugo.io/t/cant-insert-shortcode-parameter-without-quotation-marks/1481/5 "2015-07-29T10:15:34Z")

</div>

> [@digitalcraftsman](#):
>
> \<script type=“math/tex” \>{{ .Inner }}\</script\>

Try:

```auto
<script type="math/tex" >{{ .Inner | safeHTML }}</script>

```

---

<div class="post-metadata">

**Author:** ![digitalcraftsman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/digitalcraftsman/32/4142_2.png) [@digitalcraftsman](https://discourse.gohugo.io/u/digitalcraftsman)\
**Post date:** [July 29, 2015, 10:43am UTC](https://discourse.gohugo.io/t/cant-insert-shortcode-parameter-without-quotation-marks/1481/6 "2015-07-29T10:43:44Z")

</div>

> [@bep](#):
>
> \<script type=“math/tex” \>{{ .Inner | safeHTML }}\</script\>

I gave it a try, but then I get the following error message:

> executing “theme/shortcodes/katex.html” at : wrong type for value; expected string; got template.HTML

Converting `.Inner` to a string with

`<script type="math/tex" >{{ (printf "%s" .Inner) | safeHTML }}</script>`

removed the error message, but the equation is still in quotes. It seems, that it would be easier to drop this optional feature for a theme.

---

<div class="post-metadata">

**Author:** ![mattstratton](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mattstratton/32/24584_2.png) [@mattstratton](https://discourse.gohugo.io/u/mattstratton)\
**Post date:** [November 20, 2015, 7:28pm UTC](https://discourse.gohugo.io/t/cant-insert-shortcode-parameter-without-quotation-marks/1481/7 "2015-11-20T19:28:55Z")

</div>

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):

```auto
      {{ range $.Site.Data.events }}
        {{ if eq .status "current" }}
          ['{{ .city}} ', {{ .coordinates | safeHTML }}],
        {{ end }}
      {{ end }}
    ];

```

The problem is, the output then looks like this:

```auto
    var markers = [

          ['Kiel', "47.609895, -122.330259"],
    ];

```

Google Maps requires the coordinates to NOT be in quotation marks. Suggestions?

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [November 20, 2015, 8:13pm UTC](https://discourse.gohugo.io/t/cant-insert-shortcode-parameter-without-quotation-marks/1481/8 "2015-11-20T20:13:47Z")

</div>

This may help:

> <https://github.com/gohugoio/hugo/commit/c5a4c07b892128f36ec4638bfd44e5404437e066>

---

<div class="post-metadata">

**Author:** ![mattstratton](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mattstratton/32/24584_2.png) [@mattstratton](https://discourse.gohugo.io/u/mattstratton)\
**Post date:** [November 20, 2015, 8:21pm UTC](https://discourse.gohugo.io/t/cant-insert-shortcode-parameter-without-quotation-marks/1481/9 "2015-11-20T20:21:42Z")

</div>

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 ☹
