Ignore specific syntax in shortcodes

Hello everyone,

I created a shortcode which uses the .Inner content, but there is one problem. Sometimes, specific parts are just not being displayed, because they’re apparently recognized as some syntax similar to HTML used in Markdown, which is being ignored.
Let me make an example.

{{< codeblock `c#` >}}var x = obj.GetComponent<Type>();
{{< /codeblock >}}

outputs only this in the end:

var x = obj.GetComponent();

So <Type> is simply being ignored.

This is the relevant part of the shortcode:

{{ $lang := .Get 0 }}
{{ $content := .Inner }}
<pre><code class="{{ $lang }}">{{.Inner}}</code></pre>

How could I get rid of this behavior and simply output the content as is? Important to mention: There are specific situations where I want HTML to influence the content (for example to mark text as bold with the tag), but in this case, I want to output the content as is.
Thank you very much!

In the shortcode template, try out the various safe functions like for example:
{{ .Inner | safeHTML }}

1 Like

Thank you very much for your response.

{{ .Inner | safeHTMLAttr }}

seems to solve this problem.

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