gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.37k stars 7.43k forks source link

Escape shortcodes while using RenderString #10058

Open xoxys opened 2 years ago

xoxys commented 2 years ago

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.101.0-466fa43c16709b4483689930a4f9ac8add5c9f66 linux/amd64 BuildDate=2022-06-16T07:09:16Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes

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

image

This snipped was rendered without issues while using .RenderString. With the current version of hugo this is no lomger 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

What's the right way to escape shortcode snippets while using RenderString?

bep commented 2 years ago

What's the right way to escape shortcode snippets while using RenderString?

The way you show above, but I suspect you have a case of "double rendering" of your markdown which would produce the situation you describe.

I suggest you take further trouble shooting at:

https://discourse.gohugo.io/

bep commented 2 years ago

I'm reopening this as you may have a point that there is an issue worth fixing. I'm not sure what that fix should be so open to suggestions.

jmooring commented 1 year ago

Details, including a workaround: https://discourse.gohugo.io/t/40292/4

xoxys commented 1 year ago

Sorry, but it feels a bit odd how the project deals with reported issues sometimes...

I have reported the issue here, then the issue was closed pretty fast. As recommended, I have started a discussion on the forum (https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331). The issues were reopened because this seems to be a valid issue, but nobody has linked the forum discussion. Now another forum discussion was needed to notice that the problem with “that” is that it doesn’t yet provide any meaningful detail?? That's a bit annoying, especially as nobody has ever again requested more details during the conversation... :shrug:

bep commented 1 year ago

Sorry, but it feels a bit odd how the project deals with reported issues sometimes...

I apologize. We're short on staff, which means we need to be a little "over effective".

My 50 cents here:

xoxys commented 1 year ago

I understand that as well, no worries.

I suggest you start by looking into your own templates and make sure you don't do that.

As discussed on the forum, handling this in the theme isn't that simple in some situations as well. However, I can stick to the workaround from https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331/6 for now. Thanks for your work.