Parse .Inner in shortcode

Hi,
(totally newbie to both hugo and go)

I want to pass in js code from .Inner var.

Shortcode (p5-inner.html) is:

{{ $id := .Get `id` }}

<div id="{{ $id }}"></div>
<script>
  new p5((p) => {
   {{ .Inner }}
  }, "{{ $id }}" );
</script>

Shortcode is called as:

{{< p5-inner id="codeid" >}}
  p.setup = function () {
    p.createCanvas(400, 400);
  };
{{< /p5-inner >}}

Got:

<div id="codeid"></div>
<script>
  new p5((p) => {
   "\n  p.setup = function () {\n    p.createCanvas(400, 400);\n  };\n"
  }, "codeid" );
</script>

But I need:

<div id="codeid"></div>
<script>
  new p5((p) => {
    p.setup = function () { 
    p.createCanvas(400, 400); 
  };
  }, "codeid" );
</script>

Tried both chomp and trim without success. How can I make it work?

Try

{{ .Inner | safeJS }}

But note that if you’re content isn’t trusted, you’re opening up for XSS injection.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.