Escape shortcodes while using RenderString

Hi,

In the past it was possible to escape shortcode syntax e.g. in a code block like this:

This code was working without issues in Hugo < 0.100 while using .RenderString. With the current version of hugo this is no longer possible and result in the following error:

hugo v0.101.0-466fa43c16709b4483689930a4f9ac8add5c9f66 linux/amd64 BuildDate=2022-06-16T07:09:16Z VendorInfo=gohugoio
Error: Error building site: "hugo-geekdoc/exampleSite/content/en/shortcodes/katex.md:9:1": failed to render shortcode "columns": failed to process shortcode: "hugo-geekdoc/exampleSite/themes/hugo-geekdoc/layouts/shortcodes/columns.html:4:14": execute of template failed: template: shortcodes/columns.html:4:14: executing "shortcodes/columns.html" at <$.Page.RenderString>: error calling RenderString: "hugo-geekdoc/exampleSite/content/en/shortcodes/katex.md:4:1": failed to extract shortcode: template for shortcode "myshortcode" not found

The used columns shortcode is pretty simple:

According to my issue Escape shortcodes while using RenderString · Issue #10058 · gohugoio/hugo · GitHub this might be related to some kind of “double rendering” but I have no idea where double rendering should happen… Removing $.Page.RenderString from the shortcode will result in not rendered markdown at all. Any idea?

  • In your case .Inner comes from a content file in /content which has already rendered any shortcode. So the string {{</* myshortcode */>}} is now rendered to {{< myshortcode >}}
  • And then, when you pass {{< myshortcode >}} to RenderString the comments are lost and Hugo will try to find the shortcode.

I don’t understand your site in detail, but I suspect you want to drop the RenderString in this case.

Well I want to render markdown in the {{< columns >}} shortcodes content. Removing RenderString results in completely unrendered markdown:

image

Try:

{{% columns %}}

...

{{% /columns %}}

The {{% delimiter tells Hugo that the .Inner content is markup/markdown.

This does not render the HTML within the range loop properly:

 {{ range split .Inner "<--->" }}
    <div class="gdoc-columns__content gdoc-markdown--nested flex-even">
      {{ . }}
    </div>
  {{ end }}

This shortcode is intended to split the inner content of {{% columns %}} shortcode on the delimiter <---> and put the separated content in a div to display it as columns.

I can work around it by using a template:

<div class="gdoc-columns flex flex-wrap flex-mobile-column">
  {{ range split .Inner "<--->" }}
    {{ template "column" . }}
  {{ end }}
</div>

<!-- templates -->
{{- define "column" }}
  <div class="gdoc-columns__content gdoc-markdown--nested flex-even">
    {{ . | safeHTML }}
  </div>
{{- end }}

which produces the expected result:

No idea if this is the intended way, feels more complicated as it should be.

I don’t have a good answer for you on this one, it seems, so I have reopened the GitHub issue:

Thanks for reopening the issue, I’m also not sure yet how a fix could look like.