Markdown table of contents generator
Paste a README or any Markdown file and copy a ready-made table of contents. Links use the same anchor rules as GitHub, including numbered duplicates, and headings inside code blocks are ignored.
Runs in your browser: nothing you enter is sent anywhere.
How to use it
- Paste your Markdown.
- Choose the first and deepest heading level to include. A document’s single H1 title is usually left out, so the default starts at H2.
- Pick dashes, stars or numbers, and copy the result into your document, usually right under the title.
How it works
Every # heading gets an anchor. Nesting follows the heading levels: a heading is a child of the closest earlier heading with a lower level, so a jump from H2 to H4 is indented only one step. Numbered lists restart under each parent and are indented by three spaces so they keep working as sub-lists.
Example
## C++ & Go?
gives - [C++ & Go?](#c--go): the characters + & ? are removed and each of the two spaces left around the ampersand becomes a hyphen.
Tips
- Add the contents again after you rename a heading, since the anchors change with the text.
- Emoji in headings are removed from the anchor, as on GitHub.
Frequently asked questions
How are the anchors made?
The heading text is lowercased, characters other than letters, numbers, spaces, hyphens and underscores are removed, and spaces become hyphens. Inline markup such as links, backticks and bold is stripped first. This follows how GitHub names its heading anchors.
What about two headings with the same text?
The second gets the suffix -1, the third -2, and so on, as on GitHub. Headings outside the chosen levels still count, because they take up names too.
Will the links work outside GitHub?
Other sites may build anchors differently. GitLab and many static site generators are close but not identical, so check a link or two after you paste the table.
Are underlined headings supported?
Only headings that start with # are read. Headings written with a line of === or --- underneath are not included.
Are headings in code blocks listed?
No. Lines inside fenced code blocks (three backticks or tildes) are skipped, so a shell comment starting with # does not appear in the contents.