0.55 - What am I doing wrong?

I have an extremely simple shortcode that I use to increase the font of the first paragraph:

<p class="lead">{{ .Inner  }}</p>

With the new update (0.55) if I use Markdown links, they don’t get markdownified (I get the raw output)?

I.e. they appear [like this](https:example.com)

I was under the impression that shortcodes now get rendered to Markdown? Or am I reading the release notes wrong?

I have fixed the issue by using:

{{ $_hugo_config := `{ "version": 1 }` }}

But I can’t help but think I am not understanding things as well as I should.

Any ideas? Is this expected behavior?

Edit: Deleted original comment. See bep’s post below.

1 Like

@zwbetz Thanks for your example.

Unfortunately, I have been using the shortcode method as you specify, and it does not seem to render properly. See example below:

{{% first %}}this is my inner text{{% /first %}} 

I’ll have to try using markdownify, but I wonder if this is a bug. I have some other shortcodes that didn’t work properly, but just added the version 1 code to all my shortcodes. It may be a day or two before I can spend time looking at all the different issues in detail.

I suspect this may be a bug, but I will need to do some more testing first.

In the above, “this is my inner text” is sent to the markdown renderer (I assume Blackfriday).

The change we did in 0.55 was unfortunate, but I think we had to do it to go forward.

The benefit gets obvious when you have shortcodes that produce markdown with headers (ToC) and footnotes. These benefits will be even more visible in the future.

What I think the main problem people are now seeing is when they have a shortcode similar to this:

<div class="foo">{{ .Inner }}</div>

If you then do

{{% shortcode %}}**Bold** text{{% /shortcode %}}

What is then sent to Blackfriday is <div class="foo">**Bold** text</div>, which Blackfriday treats as raw HTML and ignores.

There are 2 workarounds for the above:

  1. Use markdownify, e.g.:
<div class="foo">{{ .Inner | markdownify }}</div>
  1. {{ $_hugo_config := { “version”: 1 } }}
3 Likes

@bep That is very helpful thanks. I understand it now, so can fix my shortcodes, no problem.

Thanks.

1 Like

One more question:

When this is our shortcode

<div class="foo">{{ .Inner }}</div>

should one rather use

{{% shortcode %}}**Bold** text{{% /shortcode %}}

or

{{< shortcode >}}**Bold** text{{< /shortcode >}}

{{% … %}} seems obsolete for this usecase?!

@grob If I am going to use:

{{ .Inner | markdownify }} Then I won’t need %. I will just use < >

However, if I use {{ $_hugo_config := { “version”: 1 } }} then I will use %.

I just tested on my example, and it doesn’t appear to matter which method I use. Both render correctly. However, there is no need to send the html to markdown render (even though Bep indicated this is being treated as raw), so < > is what I will go with.

Yes, for this particular use case, that is true.

Yes. So, there is a history behind all of this, and there are several reasons why you don’t want to send your inner content to Blackfriday because you may get unexpected result (so use “{{<”).

1 Like

Thanks to both of you! I will go with {{< … >}} for this case.

I was wondering what {{% … %}} is for now (I did not quite get it here), but this issue comment makes it clear.

Thank you, bep + team, for your work and patience!

Still playing a bit.

I think the confusion is that this works as before 0.55:

{{% shortcode %}}**Bold** text{{% /shortcode %}}

but this does not:

<div>
{{% shortcode %}}**Bold** text{{% /shortcode %}}
</div>

That’s probably the intended behaviour.