A must-have for any document longer than a page. Place @toc where you want the contents list and the extension takes care of the rest: headings are collected, anchor IDs are assigned, and a navigable nested list is rendered -- with filtering by level and configurable output style.
composer require alto/commonmarkuse Alto\CommonMark\Extension\TableOfContents\TableOfContentsExtension;
use League\CommonMark\Environment\Environment;
$environment = new Environment();
$environment->addExtension(new TableOfContentsExtension());@toc
@toc {min: 2, max: 3, title: "Contents", style: ordered}min_level/max_level: heading level bounds.style:bulletorordered.title,class,id,marker: output/customization options.
# Guide
@toc {min: 2}
## Intro
## Setup
### Advanced Setup
This extension is actively developed in the alto/commonmark monorepo.
MIT License -- Simon André & Alto