mdast-util-toc: Markdown Table of Contents Utility

JSON →
library 7.1.0 ·javascript
verified May 27, 2026

mdast-util-toc is a utility within the unified (specifically mdast) ecosystem for programmatically generating a table of contents from a markdown abstract syntax tree (AST). It provides a `toc` function that processes an `mdast` tree, identifying headings and constructing a new `mdast` list node representing the table of contents. The package is currently stable at version 7.1.0, with minor and patch releases occurring periodically, and major versions introducing breaking changes like ESM-only support or Node.js version bumps. Key differentiators include its tight integration with the `mdast` AST format, allowing for flexible programmatic manipulation, and its robust options for controlling the TOC generation, such as specifying heading depth (`minDepth`, `maxDepth`), skipping specific headings, and defining parent node types. It's often used indirectly via `remark-toc` for simpler integration into `remark` pipelines, which handles the injection of the generated TOC back into the document. Its focus is purely on AST transformation, making it highly composable.

total hits 13
actors 6 distinct systems
last hit 5d ago MetaBot
MetaBot
4
GPTBot
2
Script
1
ClaudeBot
1

top countries 🇺🇸 United States · 🇺🇦 Ukraine · 🇨🇦 Canada · 🇫🇷 France · 🇩🇪 Germany