H headers do not fall into the TOC Shortcode

I figure out how to add H headers to the TOC

{{% context %}}

## Toc Test

{{% /context %}}

In this form, everything works, but if I do this

{{% context %}}
{{% context %}}

## Toc Test

{{% /context %}}
{{% /context %}}

The header misses the TOC

My simplified shortcode looks like this

<section>
{{ .Inner }}
</section>

I found a strange pattern. If you do like this

{{% context %}}
{{< context >}}

## Toc Test

{{< /context >}}
{{% /context %}}

Then everything works. What?

What’s the difference between using ‘<’ or ‘%’?

But it doesn’t work like that anymore. What’s going on here anyway?

{{< context >}}
{{% context %}}

## Toc Test

{{% /context %}}
{{< /context >}}

Means “process the inner content as Markdown”.

{{< means leave the inner content as is.

This will however have different meaning for the outer-most shortcode tag. If you use {{% somewhere nested, that shortcode’s inner content will be rendered as Markdown on its own – which is the reason it does not show up in the outer ToC.

That is, there is no way to do it the way I want, no? Only use such a construction?

{{% context%}}
{{<context>}}

To put your question into its original perspecitve: There is no way to tell Goldmark (the Markdown renderer we use as default) that what’s inside the section is Markdown.

But you can generate this ToC client side.

That’s what I would call “a dirty hack”. I think you are trying to do something weird inside of the context shortcode.

  1. The ToC is working with headers, why would you have the need to nest headers?
  2. {{% means “process markdown in what you return” as an order to Hugo. Are you aware, that it can only return processed markdown and putting it inside of each other ends it up in a loop that processes because it needs to process before the other once can process? Process?

I would say this is probably more or less something that you need to work through with a .Scratch or maybe take a step or two back and rethink the whole construction. Because see 1. If it’s about ToC there is probably no need to nest headings or whatever happens in that shortcode.

Nothing weird, just this kind of layout and markup. Sometimes shortcodes overlap!

To make such a break visual, I put the chapter in a shortcode