10.2 Notenik Markdown Parser ↑
10.2.16 Generate a Note Table of Contents
As an extension to the original Markdown spec from John Gruber, a Table of Contents for a single Note’s body field can be generated dynamically, using the Note’s embedded headings as the items to be listed.
The generated HTML will display the ToC using unordered list tags, nesting where appropriate. Each ToC entry will link to its corresponding heading, relying on Heading ID Generation to establish the targets for the links.
Although dynamic Table of Contents generation for Markdown is a feature of great interest to many Markdown authors, there is unfortunately no standard syntax for extending Markdown to generate such a thing.
Notenik currently recognizes several different ways of invoking this feature.
Place the literal
[toc]
on a line by itself. This follows the Typora precedent.Place the literal
{:toc}
on a line by itself. This follows the kramdown precedent.Place the literal
{{toc}}
on a line by itself. This follows the MultiMarkdown precedent.
The resulting table will contain all of the headings found in the Markdown following the toc
line itself.
If you wish to limit the heading levels included in the table of contents, place one or two digits following the toc
literal. The first digit will be used as the logically highest (but numerically lowest) heading level to be included in the table of contents. For example, the digit ‘2’ will exclude level 1 headings from the table. The second digit will be used as the logically lowest (but numerically highest) heading level to be included.
For an example, see the following line:
{{toc:2-3}}
This line would generate a Table of Contents including heading levels 2 and 3.
The following would be excluded:
- Level 1 Headings,
- Level 4 - 6 Headings,
- Any Level 2 - 3 Headings preceding the
toc
line.
Note that, when using Merge Templates and converting Markdown to HTML, you will likely also need to use the Variable Modifier identified as the Wiki-Style Links Mod, typically with a value of ‘w2
’, in order to make sure that this command resolves effectively, since it generates wiki-style links in Markdown before the conversion to HTML takes place.