All tools

Markdown Table of Contents Generator

Code

Scan a Markdown document's ATX headings and build a nested table of contents with GitHub-style anchor slugs, disambiguating duplicate headings automatically

Paste a Markdown document and get back a ready-to-paste table of contents: a nested bullet or numbered list of links pointing at GitHub-style anchor slugs for every heading in range. It reads only ATX-style headings (one to six hash marks), skips anything inside a fenced code block so a heading-shaped comment in a code sample never becomes an entry, and strips inline formatting like bold, code spans, and links from the heading text before slugifying it. Duplicate headings get the same -1, -2 suffix disambiguation GitHub's own renderer uses, so the anchors match what GitHub would actually generate for the same document.

markdowntocheadingsdocumentationslug

How to use Markdown Table of Contents Generator

  • 1.Paste a Markdown document, or try the sample doc to see the output shape.
  • 2.Optionally switch to a numbered list if your documentation site expects ordered TOC entries.
  • 3.Copy the generated table of contents and paste it near the top of your document.

Frequently asked questions

Does this handle setext-style headings (underlined with === or ---)?
No, only ATX-style headings (# through ######) are recognized. Setext headings are rare enough in practice that most Markdown TOC tools skip them too.
Why did a heading inside a code block get skipped?
Headings inside fenced code blocks (``` or ~~~) are intentionally ignored, since a # inside a code sample (a shell comment, for example) isn't a real document heading.
How are duplicate headings handled?
The first occurrence of a heading text gets its plain slug, and each further duplicate gets a -1, -2, ... suffix appended, matching the disambiguation GitHub's own Markdown renderer uses for repeated headings.
Will the anchor slugs match my static site generator's output exactly?
They follow GitHub's convention (lowercase, non-word characters stripped, spaces to hyphens), which most popular renderers copy closely, but some tools use a different slugify algorithm, so always spot-check the links after pasting.

Use via API, SDK, or MCP

cURL# Free: 1,000 req/day · Pro: 10,000 req/day
curl -X POST https://api.utilix.tech/v1/tools/markdown-toc-generator \
  -H "Authorization: Bearer utx_live_..." \
  -H "Content-Type: application/json" \
  -d '{"markdown":"# Title\n\n## Section One\n\n## Section Two\n"}'

Get an API key from your dashboard · Full API docs →