Custom shortcode not rendering markdown

I created a shortcode like so:

<p>{{ .Inner }}</p>

This

{{< myshortcode >}}
**text**
{{< /myshortcode >}}

Literally renders text without Markdown formatting as expected.

However

{{% myshortcode %}}
**text**
{{% /myshortcode %}}

renders an HTML comment saying <!-- raw HTML omitted -->

If I understand the docs correctly this is how you are supposed to add Markdown to a shortcode. What am I doing wrong?

Thanks!

In your example, when you wrap .Inner in a p element, you are mixing HTML with markdown. The markdown renderer is simply following the (somewhat) complex rules for rendering HTML blocks:

https://spec.commonmark.org/0.31.2/#html-blocks

I think you want to do this instead:

<p>{{ .Inner | .Page.RenderString }}</p>

and call it with:

{{< myshortcode >}}
**text**
{{< /myshortcode >}}
1 Like

This works, thank you so much!

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