Skip to content
gohacks.dev
Tooling

Markdown Table of Contents Generator

Generate a table of contents for a Markdown file with GitHub-compatible anchor links, a chosen range of heading levels and nested bullets.

Free · No sign-up · Your inputs stay in your browser

Input

Generate a table of contents for Markdown

Output

Table of contents

6 entries

Anchors follow GitHub's rules: lowercase, punctuation removed, spaces to hyphens, and -1, -2 appended to repeated headings, so the links work in a README. Headings inside fenced code blocks are skipped.

Runs in this browser. Nothing you paste is sent to a server.

GitHub's anchor rules

GitHub creates an id for every heading from its text. Two headings with the same text get section and section-1, which is the detail most hand-written tables of contents get wrong. GitLab and many static site generators follow similar rules, but check yours if anchors use a different slug function.

Do you need one

GitHub already shows an outline button for README files, and most documentation themes build a sidebar from headings. A written table of contents still helps in long files viewed elsewhere, such as on npm or Packagist, or printed.

Share

Frequently asked questions

Why do headings inside code blocks not appear?
Lines starting with # inside a fenced code block are code, such as shell comments, not headings. The generator skips everything between fences.
How do I keep the table of contents up to date?
Regenerate it when headings change, or use an editor extension or a pre-commit hook such as markdown-toc that rewrites it between marker comments.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools