Exclude some head levels from TableOfContents

The .TableOfContents is a really great feature. Easy to drop in. I’d like to be able to custom the heading levels though. IOW, I have pages that might go to heading level depth of 4 but I want to restrict the mini toc to display only up through level 3.

I can see in Hugo’s own implementation of http://gohugo.io/tutorials/creating-a-new-theme/ that h3s from the source file in content/tutorials file aren’t appearing in the generated toc. In my default single.html I’ve implemented to TOC as follows.

    <div id="toc" class="large-3 columns {{ if gt (len .TableOfContents) 2500 }}compact{{ end }}">
 On this page:
    {{ .TableOfContents }}

I’m not parameterizing the toc value in the content files. I want a toc on every page.

“Hugo’s own implementation” is my (not so pretty) CSS:

There are currently no easy way to remove them entirely from the generated output. In a future Hugo that may be fixed.

1 Like

Thanks Bep. Clever use of css indeed. I’ll look for an enhancement request for TableOfContents on GitHub. For documentation sets, definitely would be useful to configure this more easily.