Table of Contents empty when headers within shortcode

I have the same problem as mentioned here: Why TOC is not working?

The table of contents is working fine - as long as the headers are outside a shortcode. Once they are in a short code enclosing the headers the {{ .TableOfContents }} remains empty.

My shortcode basically assigns a class to the paragraph:
htmlclass:

{{ $contentclass := .Get 0 }}
<div class= {{$contentclass}} >
{{ .Inner }}
</div >

In markdown:

{{% htmlclass "content-body-section" %}}

## First H2
Loret Ipsum
{{% / htmlclass %}}

{{% htmlclass "content-body-section" %}}

## Second H2
Loret Ipsum
{{% / htmlclass %}}

## Third H2

In the TOC - only the “Third H2” is listed - the other ones are ignored.
Am I doing something wrong or is this the default behaviour for TOC?

A post was merged into an existing topic: Why TOC is not working?