Generate a Table of Contents (TOC) from Markdown headings. Supports heading extraction, multiple output formats, and configurable level filtering.
Documents
Markdown TOC Generator
Try itGenerate and update table-of-contents (TOC) sections for Markdown files. Use when working with long Markdown documents, READMEs, or technical docs that need a navigable TOC, or when asked to add/update a table of contents in a .md file.
What it does
Generate and update table-of-contents (TOC) sections for Markdown files. Use when working with long Markdown documents, READMEs, or technical docs that need a navigable TOC, or when asked to add/update a table of contents in a .md file.
The skill document
Markdown TOC Generator
Generate a table of contents from the headings in a Markdown file and insert or refresh it.
Quick start
python3 scripts/generate_toc.py [--max-depth 3] [--in-place]
- Without
--in-place: prints the TOC to stdout. - With
--in-place: inserts the TOC right after the first heading (or updates an existing<!-- toc -->block).
TOC placement
- If the file contains
<!-- toc -->and<!-- /toc -->markers, the block between them is replaced. - Otherwise the TOC is inserted immediately after the first
#heading.
Anchor rules
- Lowercase the heading text.
- Replace spaces with hyphens.
- Strip punctuation except hyphens and underscores.
- Duplicate anchors get
-1,-2, … suffixes.
Examples
# Print TOC only
python3 scripts/generate_toc.py docs/guide.md
# Insert / refresh TOC in place
python3 scripts/generate_toc.py README.md --in-place --max-depth 4
Related skills
Generate a table of contents (TOC) for any Markdown file by extracting its ATX headings (# ..
Get Markdown that renders correctly in GitHub, MDX, Pandoc, docs sites, Slack, Notion, and other parsers.
Scan a directory of Markdown files, extract titles/headings/frontmatter, build a searchable index JSON, and output a concise summary report. Use when you need to inventory, catalog, or make a folder of .md files discoverable without reading each file individually.
Format and lint markdown files for consistency and readability. Use when Codex needs to normalize markdown documents, fix heading levels, standardize link fo...
Convert a git log, commit list, or release notes into a polished, user-facing changelog. Use when writing release notes, generating a CHANGELOG.md entry, or...