I am trying to do two things with the Table of Contents (ToC), neither of which seem to be possible without the existence of a Markdown render hook for the ToC.
Firstly, I would like to be able to parse multiple files for headings. For example, say I have a Page Bundle that looks like so:
foo/
├── index.md
├── appendices.md
Both index.md
and appendices.md
contain Markdown-formatted headings. Then, in my template, I have something like:
<section>
{{ .Content }}
</section>
{{ if fileExists ( path.Join $.Page.File.Dir "appendices.md" ) }}
<section>
<h2 id="appendices">Appendices</h2>
{{ $file := path.Join $.Page.File.Dir "appendices.md" | readFile }}
{{ $file | .RenderString }}
</section>
{{ end }}
Currently, .TableOfContents
only takes into the account the headings in the index.md
file. As a workaround, I’ve added a appendices
field to the content front-matter where I list the headings, and then I manually add the second list after the call to .TableOfContents
in my template, but an automated solution would be preferable (perhaps with some sort of .TableOfContents.ParseAdditionalHeadings
method that would be provided a filepath, parse it for headings and then append them to the existing .TableOfContents
tree).
There’s one unresolved six-year-old thread about being able to access the Table of Contents tree, but that’s all I found.
Secondly, none of the settings for autoHeadingIDType
in the Goldmark config seem to be able to handle HTML within a Markdown heading. For example:
## Something with a <q>quote</q>
…will get converted to an anchor of #something-with-a-qquoteq
.
It is possible to manually specify the desired ID (e.g., ## Something with a <q>quote</q> {#something-with-a-quote}
), but I have a lot of content and an automated solution would be far preferable. If there were a render hook available, I could manually run the heading title through plainify
when coming up with the IDs for the headings.