Table of Contents: Wrong Anchors Break Every Link

Open Tool Markdown Table of Contents

A contents list mirrors the headings

A table of contents is generated from heading lines: scan lines starting with hashes or heading tags, expand by level, and mint an anchor for each entry. Anchors derive from heading text, usually lowercased, spaces turned to hyphens and punctuation dropped, while Chinese headings keep their characters and get percent-encoded in links. Three outputs serve different needs: linked entries jump straight to sections on the web, indented plain text reads as an index in documents, and numbered levels show structure and order at a glance in specification writing.

Steps

  1. Paste Markdown or an outline with intact heading lines.
  2. Choose linked, indented or numbered output.
  3. Run it and compare entry count with the real heading count.
  4. Check anchor spelling against each target heading.
  5. Copy the block to the top of the document and test the first three links and the last.
  6. Regenerate after body edits so the list never drifts.

Anchor rules, duplicates and levels

Anchor rules differ across platforms, so the same heading may yield different results in GitHub style and a blog engine, and every copy needs testing where it lands. Duplicate headings collide on one anchor, with numeric suffixes from the second onward, and manual edits must keep them aligned or links fall back to the first. Level jumps scramble numbering, leaving gaps where a fourth-level heading follows a second. Chinese anchors appear percent-encoded in the address bar, which is normal. Contents never lift ranking but do improve long-form reading.

Common mistakes

Anchors mismatched in case or punctuation make links dead. Duplicate suffixes updated in the list but not in links. Paragraphs pulled in as entries, doubling the list. Level jumps leaving numbering gaps. Headings edited without regenerating. And a contents block buried at the page bottom where nobody sees it.

Where a contents list is noise

Two or three short sections read faster by scrolling than by a list. It cannot replace site navigation, which handles cross-page structure. Auto-generated pages need anchors matching rendered identifiers, retested after template changes. Multilingual sites generate per language rather than sharing anchors. And stuffing keywords into contents entries makes a document look cluttered.

⏫︎