# Markdown TOC Generate a GitHub-style table of contents from Markdown headings. ``` python scripts/run.py README.md python scripts/run.py README.md --min-level 2 --max-level 3 python scripts/run.py README.md --bullet '1.' cat doc.md | python scripts/run.py - ``` Pure Python stdlib (`re`). Produces `- [Title](#anchor)` lists. --- name: markdown-toc display_name: Markdown TOC description: "Generate a table of contents from Markdown headings with GitHub-style anchor links. Triggers: table of contents, markdown toc, generate toc, heading links, doc outline." --- # Markdown TOC Generate a nested table of contents from Markdown headings. ## When to use The user has a Markdown document and wants a clickable table of contents with anchors that match how GitHub renders heading links. ## How to use Run `scripts/run.py` with the file (or stdin): - `python scripts/run.py README.md` — full TOC. - `python scripts/run.py README.md --min-level 2 --max-level 3` — only `##` and `###`. - `python scripts/run.py README.md --bullet '1.'` — ordered list. - `cat doc.md | python scripts/run.py -` — read from stdin. Output is indented Markdown list items like `- [Title](#title)`. ## Pitfalls - Anchors use GitHub's slug rules: lowercase, spaces to hyphens, punctuation stripped, and duplicate headings get `-1`, `-2` suffixes. - Headings inside fenced code blocks (```` ``` ```` or `~~~`) are ignored. - Only ATX headings (`#`..`######`) are detected; underline-style (Setext) headings are not.
Markdown TOC by langbot-team
Generate a table of contents from Markdown headings with GitHub-style anchor links.
Loading...