PAGE.Fragments and Asciidocs

I’ve been trying to create a linked table of content on the sidebar of my documentation pages. It did work until I switched to asciidocext in my markup configuration.

The pages are being processed correctly. Headings are getting their IDs but the .Fragment variable is empty and so are all the related variables. Reading the documentation at Fragments | Hugo I might be tempted to think this feature only works with Markdown.

I’m here to either confirm this suspicion, or stand corrected, in case I’m missing something. Is there any way to get the .Fragments variable populated also when using markups different from goldmark?

The Fragments method is applicable to markdown rendered with Goldmark.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.

The statement above is false.

Regardless of the markup.asciidocExt.preserveTOC setting, the Fragments data structure is populated provided that you have set the AsciiDoc :toc: document attribute. For example:

---
title: My AsciiDoc Article
---

:toc:

## Section 1

## Section 2

To inspect the data, place this in your template:

{{ with .Fragments }}
  <pre>{{ debug.Dump .Headings }}</pre>
  <pre>{{ debug.Dump .HeadingsMap }}</pre>
  <pre>{{ debug.Dump .Identifiers }}</pre>
{{ end }}
1 Like