Loading...
Preparing your workspace
Loading...
Preparing your workspace
Generate table of contents (TOC) for Markdown documents automatically. Extract headings from Markdown files, create nested TOC with proper indentation, and generate anchor links compatible with GitHub, GitLab, and other Markdown processors.
Note: AI can make mistakes, so please double-check it.
Learn what this tool does, when to use it, and how it fits into your workflow.
The Markdown TOC Generator builds a table of contents for your Markdown documents automatically. You paste or type Markdown into the editor, and the tool scans your headings, builds a nested list of links, and outputs either Markdown list syntax or HTML list code depending on your settings. It supports different anchor presets so that generated links work with common Markdown viewers.
This solves a real problem for writers and developers. Long Markdown files are hard to navigate without a table of contents. Manually creating a TOC is tedious and easy to forget when headings change. Updating anchor links by hand is error prone, and a small typo can break navigation. The generator keeps your TOC synchronized with the headings in your content.
The tool is for people who write documentation, README files, tutorials, or technical blogs in Markdown. It works well for beginners who do not want to learn every detail of anchor formatting, and for experienced users who want a quick, reliable way to keep their TOC up to date. No programming is required beyond basic comfort with Markdown itself.
Markdown is a plain text format for writing content with simple syntax for headings, lists, links, and more. Headings are written with one or more # characters at the start of a line, from H1 (#) to H6 (######). A table of contents is a list of links at the top of a document that point to these headings, making it easier for readers to jump to sections.
Most Markdown processors convert headings into HTML elements with id attributes derived from the heading text. For example, a heading like “## Install and setup” might become an h2 element with id="install-and-setup". A TOC entry for this heading uses a link to #install-and-setup. The exact rules for building ids differ between platforms such as GitHub, GitLab, and Bitbucket.
Manually writing a TOC means reading through your document, finding each heading, converting the text into the correct slug according to your platform’s rules, and then writing Markdown list items with proper indentation for different levels. When you rename a heading or change its level, you must remember to update the TOC. In practice, this often does not happen, and TOCs drift out of date.
The Markdown TOC Generator automates this process. It reads your content, finds headings within a configurable depth range, creates slugs using preset rules that mimic popular platforms, and outputs a formatted TOC. It also optionally skips code blocks to avoid picking up headings that appear inside fenced or inline code. An AI helper can suggest improved heading text to make your TOC clearer and more consistent.
A documentation writer preparing a long user guide in Markdown can paste the entire file into the Markdown TOC Generator. The tool reads all H1–H3 headings, builds a nested TOC list, and the writer copies it into the top of the document. When new sections are added, they paste the updated content again and refresh the TOC in seconds.
A developer maintaining a project README wants a GitHub-compatible TOC. They select the GitHub preset, keep default depth settings, and paste their README text. The generator creates anchor links that match GitHub’s slug rules, including handling spaces and punctuation correctly. The developer can then paste the TOC back into the README, confident that links will work in the repository.
A technical blogger writing multi-part tutorials wants to ensure headings are consistent and well structured. They use the Optimize feature to get heading suggestions. After reviewing each suggestion and applying the ones they like, they regenerate the TOC so that the improved headings appear in a cleaner, more readable list.
A team writing internal standards for documentation uses the generator to show examples of good headings and matching TOCs. They paste in a sample document, show how changes to minDepth and maxDepth affect the TOC, and demonstrate HTML output for tools that require explicit HTML lists.
The Markdown TOC Generator uses a clear parsing pipeline. First, it checks that the input is a non-empty string and does not exceed the maximum allowed length. It also limits the number of lines it will process to avoid memory problems on huge documents. If the input passes these checks, it prepares a version of the content—with optional removal of code blocks—specifically for heading detection.
Code block exclusion operates in two passes. It removes fenced code blocks by matching patterns starting with ``` and ending with the next ``` across multiple lines. It also removes inline code fragments enclosed in single backticks so that heading-like patterns in code are not mistaken for real headings.
Next, it splits the sanitized text into lines and loops through them. For each line, it applies a regular expression that matches one to six # characters at the start, followed by at least one space and some text. For a match, it computes the heading level from the number of # characters and trims the heading text.
The parser enforces that the heading level lies within the configured minDepth and maxDepth range. If it does, it creates a TOC item with level, original text, and a slug computed by the anchor preset function. The slug generator removes or encodes characters based on preset rules, lowercases the text, and normalizes spaces and hyphens. For example, GitHub style slugs remove non-word characters, replace spaces with hyphens, collapse multiple hyphens, and strip leading and trailing hyphens.
When formatting the TOC in Markdown mode, the tool first finds the minimum heading level among all items. It then computes indentation for each line as two spaces times (item.level - minLevel). It escapes square brackets in the heading text to avoid breaking link syntax, then writes a line in the form - [text](#slug). The lines are joined with newlines into the final output.
When formatting in HTML mode, the tool wraps all items in a single ul element. For each heading, it escapes special HTML characters in the text and writes a li with an anchor tag whose href is #slug and content is the escaped text. It does not currently nest lists by level in HTML mode; all items appear in one flat list.
The AI refinement logic validates the heading array before calling the backend. It ensures the number of headings does not exceed the limit and that each heading is a string of acceptable length. It then calls the AI service with the headings array and expects back an array of RefinedHeading objects containing original, suggested, and reason fields. The UI ensures that applying a suggestion only changes exact matches for that heading text and keeps the same heading level.
| Preset | Slug Style | Example for "My Heading!" |
|---|---|---|
| GitHub | Lowercase, remove punctuation, hyphenate spaces | my-heading |
| GitLab | Similar to GitHub, lowercase and hyphenated | my-heading |
| BitBucket | Prefix markdown-header-, hyphenate, strip invalid | markdown-header-my-heading |
| Generic | Hyphenate spaces, URL-encode result | my-heading (encoded) |
Keep your headings clear and descriptive. A good TOC reflects the outline of your document, so short but meaningful headings will make the TOC more useful. The AI suggestions can help polish wording, but the content and structure still depend on you.
Use a depth range that matches your document. For short documents, including all headings (H1–H6) can create a noisy TOC. For long, structured guides, focusing on top levels such as H1–H3 often makes navigation clearer.
Be aware that different platforms implement their own anchor logic. Always choose the preset that matches where your Markdown will be rendered. If you are unsure, test the generated TOC in your target environment to confirm links work as expected.
Do not paste extremely large files that exceed the documented limits. The tool is optimized for typical documentation and blog posts, not raw logs or huge exports. If your content is very large, consider splitting the document into smaller parts with their own TOCs.
Use the settings to exclude code blocks if your examples contain lines that look like headings. This keeps your TOC focused on actual sections of your document instead of code comments or sample markup.
After copying the TOC back into your Markdown, keep the original document under version control. When you change headings, regenerate the TOC in this tool and update it so documentation and navigation stay in sync.
Summary: Generate table of contents (TOC) for Markdown documents automatically. Extract headings from Markdown files, create nested TOC with proper indentation, and generate anchor links compatible with GitHub, GitLab, and other Markdown processors.
No headings found
Add markdown headings to generate TOC
Common questions about this tool
Paste your Markdown content into the TOC generator. It automatically extracts all headings (H1-H6), creates a nested table of contents with proper indentation, and generates anchor links that work with GitHub, GitLab, and other Markdown processors.
The generator includes all heading levels (H1 through H6) by default, creating a hierarchical table of contents. You can customize which heading levels to include based on your document structure and TOC depth requirements.
Yes, the generated TOC uses anchor links compatible with GitHub Flavored Markdown, GitLab, and most Markdown processors. The links automatically scroll to the corresponding headings when clicked in Markdown viewers.
Yes, you can customize TOC formatting including indentation style (spaces or tabs), link format, whether to include heading numbers, and the maximum depth of headings to include in the table of contents.
Copy the generated TOC and paste it at the beginning of your Markdown document (typically after the title). The TOC will automatically link to all headings in your document, making navigation easier for readers.
Stay tuned for helpful articles, tutorials, and guides about this tool. We regularly publish content covering best practices, tips, and advanced techniques to help you get the most out of our tools.