Generate a Table of Contents (TOC) from Markdown headings. Supports heading extraction, multiple output formats, and configurable level filtering.
文档
Markdown TOC Generator
试用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.
它能做什么
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.
技能文档
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
相关技能
Generate a table of contents (TOC) for any Markdown file by extracting its ATX headings (# ..
让 Markdown 在 GitHub、MDX、Pandoc、文档站、Slack、Notion 等解析器中正确渲染,并定位修复具体损坏位置。
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...