Shortcode + html

Hi, all.

I created on shortcode to manage blockquote html as:

<div class="info-quote"><p class="text-white-50">{{ i18n "quoteTitle" }}</p></div><div class="quote"><blockquote>{{ $file := .Get 0 | readFile }}{{ $file }}</blockquote></div>

Into file.md, I call as:

{{% blockquote "/content/inc/file-to-include" %}}

In this file, it wrote:

<span class="red">It appears you do not have permission to view information… </span>

blablablabla... and re-blablabla.

but, the result escape the html code !

How I can modify my shortcode to view correct embed html code?
I test with function htmlUnescape, but without success. :frowning:


PS : I run hugo v0.53 under OpenBSD 6.6!

Since your shortcode does not contain markdown instead of using % use the < > delimiters.

Also see: https://gohugo.io/content-management/shortcodes/#shortcodes-without-markdown

1 Like

OK, thanks!

If I write:

{{< blockquote >}}
<span class="red">It appears you do not have permission to view information… </span>

blablablabla... and re-blablabla.
{{< /blockquote >}}

And, convert the shortcode as:

<div class="info-quote"><p class="text-white-50">{{ i18n "quoteTitle" }}</p></div><div class="quote"><blockquote>{{ .Inner }}</blockquote></div>

It’s run!

But, If the HTML text is into in included file?
the output is escaped!

I try too, with:

{{< blockquote "/content/inc/included-file" >}}{{< /blockquote >}}

Try:

{{ .Inner | htmlUnescape | safeHTML }}

You may have to replace .Inner with however you’re reading in the text file.

Result: empty!

If I wrote as:
{{ .Inner }}{{ .Get 0 | htmlUnescape | safeHTML }}
This returns the real name string of /path/to/included-filebut not his content.

Finally, I found quasi-correct as:
{{ .Inner }}{{ .Get 0 | readFile | htmlUnescape | safeHTML }}


I obtain same result with this shortcode:

<div class="info-quote"><p class="text-white-50">{{ i18n "quoteTitle" }}</p></div><div class="quote"><blockquote>{{ $file := .Get 0 | readFile | htmlUnescape | safeHTML }}{{ $file }}</blockquote></div>

and the call, as:
{{% blockquote "/content/inc/included-file" %}}

1 Like