Markdown TOC Generator
Paste Markdown and generate a nested, linked table of contents from its headings, ready to paste back at the top of the document.
🔒 This tool runs entirely in your browser. Your files are never uploaded to a server.
Paste your own Markdown — the table of contents updates as you type.
Preview
How Markdown TOC Generator works
- Paste or type Markdown into the source box — a sample document with nested headings is pre-filled.
- The tool scans every line for Markdown heading syntax (
#through######), ignoring anything inside fenced code blocks. - Each heading is converted into a GitHub-style anchor slug and nested by its heading level to build the table of contents.
- Copy the generated Markdown list and paste it at the top of your document, or check the rendered preview to click through the links.
The method
Anchor slugs are built the same way GitHub renders them: lowercase the heading text, strip characters that
aren't letters, numbers, spaces, or hyphens, then replace spaces with hyphens. A heading like
"Basic Commands" becomes the anchor #basic-commands.
Nesting in the output list follows each heading's level relative to the shallowest heading in the document,
so a document that starts at ## is still indented correctly.
FAQ
How does the tool build the anchor links?
Each heading is slugified the same way GitHub renders Markdown anchors: the text is lowercased, punctuation is stripped, and spaces become hyphens. If two headings produce the same slug, later ones get a numeric suffix (-1, -2, …) so every link stays unique.
Does it look inside code blocks for headings?
No. Lines between triple-backtick fences (```) are skipped, so a "# comment" inside a code sample is never mistaken for a heading.
Is my Markdown uploaded anywhere?
No. Parsing and slug generation both happen in your browser with plain JavaScript — the text never leaves your device, and nothing is stored after you close the tab.
How we compare
| Feature | Online Tool Store | Writing anchors by hand | A markdown editor's built-in outline |
|---|---|---|---|
| Consistent GitHub-style slugs, including duplicates | ✓ | Error-prone | Varies by editor |
| No install or account | ✓ | ✓ | ✗ |
| Free, no watermark | ✓ | ✓ | ✓ |
Hand-written anchors drift out of sync the moment a heading is renamed, and not every editor's outline view matches GitHub's exact slug rules. If you need a TOC that links correctly on GitHub, GitLab, or any renderer that follows the same convention, generating it from the real heading text is the reliable option.