I’m trying to use a mix of markdown and nested shortcodes and I cannot get the combination to work at the same level. I’ve concocted a trivial example, although this is not my exact use case, it demostrates the problem. Given the following shortcodes:
nothing.html
{{ .Inner }}
markdown.html
{{ .Inner | markdownify }}
label.html
<span class="label">{{ .Get 0 }}</span>
In the example situation
{{< nothing >}}
## Header 1
{{< label "A label" >}}
{{< /nothing >}}
generates the following:
## Header 1
<span class="label">A label</span>
which is not correctly translating the markdown header. So, if I use the shortcode to markdownify the content:
{{< markdown >}}
## Header 2
{{< label "A label" >}}
{{< /markdown >}}
generates
<h2><a class="anchor" id="header-2"></a>Header 2</h2>
<p><!-- raw HTML omitted -->A label<!-- raw HTML omitted -->
so now the label shortcode is not generated correctly. If I used the %
tags instead of the <
in the above examples, e.g.:
{{% nothing %}}
## Header 3
{{< label "A label" >}}
{{% /nothing %}}
{{% markdown %}}
## Header 4
{{< label "A label" >}}
{{% /markdown %}}
I get the following:
<h2><a class="anchor" id="header-3"></a>Header 3</h2>
<p><!-- raw HTML omitted -->A label<!-- raw HTML omitted --></p>
<!-- raw HTML omitted -->
So it seems that I simply can’t use shortcodes and markdown at the same level within a shortcode. This is particularly a problem for me, since I used a shortcode to indicate a “section”, and within that I have a markdown table… inside the table cells, I’m trying to use shortcode for images. This completely breaks.
I found this question previously, however, the asker did not respond to @bep suggestion. I hope this example demonstrates @bep suggestion does not work either - unless I’ve missed something.
I would seem like the .RenderString
could be the answer to our problem here, so we could replace the markdownify
with .RenderString
but this doesn’t work for shortcodes (https://github.com/gohugoio/hugo/issues/6703)
My actual use case is pretty much exactly @bric3 example in the github issue: https://github.com/gohugoio/hugo/issues/6703#issuecomment-612089398
Any help is appreciated!