Generate a Markdown table of contents

Generate a Markdown table of contents from document headings with anchor links.

freeworks offlinenothing uploaded
ToolMarkdown TOC Generator
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

ATX and setext headings are collected, text is lowercased and punctuation removed for a slug, and indented links are emitted up to the selected depth. Repeated headings receive numeric suffixes.

  • Depth six covers all standard heading levels.
  • GitHub-style slugs match common repository rendering.

Worked example

Generate table of contents
Create a TOC from Markdown headings
Input
											# Introduction

## Getting Started

### Installation

## Usage
										
Output
												Level  Text             Slug
-----  ---------------  ---------------
1      Introduction     introduction
2      Getting Started  getting-started
3      Installation     installation
2      Usage            usage
											

When to use this

README contents, design-document outlines, and static-site sidebars generate heading links.

Edge cases

  • Duplicate headings need suffixes to target distinct anchors.
  • Headings inside fenced code are ignored.
  • Punctuation-only headings need an anchor fallback.

References