.Page.RenderString expands shortcodes in inline code blocks

This post is a placeholder until I get time to do a proper bug report with minimal test case and all, but I thought I would give a heads up and see if anyone else has run across this (yet).

Given a shortcode like:

{{- $curPage := .Page -}}
{{- $page_asset_name := .Get 0 -}}
{{- $page_asset := resources.Get $page_asset_name -}}
{{- with $page_asset -}}
    {{- $page_asset.Content | $curPage.RenderString | safeHTML -}}
{{- end -}}

Which is used in a content page such as (skipping the frontmatter):

{{< page-assets "hugo-debug-tables-README.md" >}}

and using an mount section in config.toml such as:

path = "github.com/danielfdickinson/hugo-debug-tables"
ignoreConfig = true
ignoreImports = true

source = "README.md"
target = "assets/hugo-debug-tables-README.md"

Any shorcodes in the README, even those in code blocks are rendered with the latest Hugo.

What should happen is that the behaviour should be the same as if the content of the README where directly in the content (that is as a normal content page), which is that shortcodes in code blocks (whether full for or just inline) are not rendered.

I’d be find with just escaping the shortcodes (as I have done as a workaround) but the backlash (\) character appears in the output, which is not quite right.

.RenderString now support shortcodes (this is very useful) and it behaves exactly the same as for content pages (e.g. site.Home.Content). You can use shortcodes in inline code blocks. This means that if you want to tell Hugo not to render any shortcode, you need to use the comment syntax, see this related issue:

1 Like

Doh! I missed that. Thank you bep.

Not sure why I thought it worked with regular content.

Also yes, shortcodes in .RenderString is very useful. Just have to fix a few things I didn’t realize were broken.

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