1001Ferramentas
📑Dev

Markdown TOC Generator

Generate the table of contents of a Markdown file from headings (#, ##, ###). Includes GitHub-style anchors. Everything in your browser.

Generate a Markdown table of contents

A long Markdown document calls for a table of contents up top, with a link to each section. The thing is, doing that by hand and keeping it in sync with the headings is a real chore. Paste your file here and the table of contents comes out ready, built from the headings themselves.

The tool reads headings from # through ######, respects the hierarchy among them, and builds the list with GitHub-style anchors, the ones that jump straight to the section on click. A repeated heading gets the -1, -2 suffix that GitHub itself adds, and anything inside a fenced code block stays out of the contents. Within seconds the list is ready to paste at the start of the document, already indented correctly at each level.

None of the text leaves your browser while it generates. Good for anyone looking after READMEs, wikis and technical docs who wants easy navigation without hand-updating the index.

Frequently asked questions

Does it pick up headings inside code blocks?
It does, and that is the biggest source of junk in the table of contents. The scan runs line by line looking for one to six # characters followed by a space, with no idea where a fenced code block starts or ends. A line such as "# install dependencies" inside a bash fence lands in the list as though it were a section. Setext headings, the ones underlined with === or ---, stay out: only the # form is recognised. Read the output over before pasting it in.
Do the anchors really work on GitHub?
In most cases, yes. The slug is the heading lowercased, with punctuation dropped and spaces turned into hyphens, which matches GitHub's rule, and accented letters survive just as they do there. The exception is a repeated heading: GitHub numbers the second one with a -1 suffix, while here both come out with an identical anchor, so the second link jumps back to the first section. Rename duplicate headings or add the suffix by hand.
The table of contents came out fully indented. How do I fix it?
Indentation comes from the heading level itself, not from the shallowest heading in the document: a ## gets two spaces even when no # exists in the file. Since plenty of READMEs use # only for the project name and open their sections at ##, the index arrives with two spaces on every line. Just strip that margin in your editor after pasting, because the relative hierarchy between levels is already correct.

Related Tools