Markdown Header Extractor

Extracts every heading from a Markdown document into an indented outline that mirrors the heading hierarchy, useful for a quick table of contents or for sanity-checking a document's structure. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-22

Overview

Introduction

A long Markdown document's structure lives entirely in its headings, but scanning past dozens of paragraphs just to see that structure is slow.

This pulls every heading out into a clean, indented outline, useful as a quick table of contents or a sanity check that a document's heading hierarchy makes sense.

What Is Markdown Header Extractor?

A heading extractor that walks a Markdown document with `marked`'s lexer, collecting every heading token along with its level.

Using the lexer rather than a `^#+` regex means a # inside a fenced code block, a shell comment, a hashtag in quoted example text, is never mistaken for a real heading.

How Markdown Header Extractor Works

Each heading token's inline Markdown (bold, code spans, links) is rendered and stripped to plain text, then added to the outline at an indent matching its heading level.

The outline uses heading level directly for indentation, so a document that jumps from an <h1> to an <h3> shows that jump in the outline's indentation rather than hiding it.

When To Use Markdown Header Extractor

Use it to generate a quick table of contents for a long README or doc before writing one by hand.

It's also useful for reviewing a document's heading structure at a glance, catching an accidentally skipped level or an unexpected second top-level heading.

Features

Advantages

  • Never mistakes a # inside a code fence for a real heading, since it uses a real parser rather than a line regex.
  • Strips inline Markdown syntax from heading text, producing a clean outline rather than raw source.
  • Runs entirely client-side with no upload required.

Limitations

  • Setext-style headings (underlined with === or ---) are recognized by the parser the same as ATX headings, but the outline itself doesn't distinguish which style was used in the source.
  • The outline reflects heading levels as written; it doesn't renumber or fix a document's heading hierarchy for you.

Examples

A document with nested headings

Input

# Guide

## Setup

### Requirements

## Usage

Output

- Guide
  - Setup
    - Requirements
  - Usage

Each heading is indented two spaces per level below the top, mirroring the document's actual nesting.

Best Practices & Notes

Best Practices

  • Use this as a starting point for a table of contents, then add anchor links manually for your target platform's linking convention.
  • Run Markdown Validator alongside this if you also want skipped heading levels flagged explicitly rather than just visible in the indentation.
  • Re-run after editing to confirm a restructured document's outline still makes sense.

Developer Notes

Heading text comes from each token's `tokens` field rendered through `marked.parseInline()` and stripped of HTML tags, not the token's raw `text` field, since `text` is the unparsed inline Markdown source and would leave literal ** or ` characters in the outline.

Markdown Header Extractor Use Cases

  • Generating a quick table of contents for a long README
  • Reviewing a document's heading hierarchy before publishing
  • Checking whether a restructured document's headings still nest correctly

Common Mistakes

  • Expecting anchor links in the output; the outline lists heading text and hierarchy only, not clickable links.
  • Not noticing a heading level was skipped, since the outline shows it as indentation rather than an explicit warning.

Tips

  • If the outline's indentation jumps by more than one level at some point, that's a skipped heading level worth checking with Markdown Validator.
  • Combine with Remove Markdown Formatting if you want the document's full body text stripped down too, not just its headings.

References

Frequently Asked Questions