Skip to content

Heading anchors and optional table of contents #4

@SyNeto

Description

@SyNeto

Goal

Generate stable anchor IDs on every heading and (optionally) a clickable table of contents at the top of long documents.

Why

GitHub does this automatically on the web. Reading the same file locally without anchors makes deep-linking and skimming harder.

Proposed approach

  • For each `h1`–`h6`, generate a slug (lowercase, dashes, deduplicated like GitHub) and inject an `id` plus a hover-revealed `<a class="anchor" href="#slug">` icon — same pattern as github.com.
  • Render a TOC at the top of the document.

Open questions

  • TOC: always-on, opt-in via a marker like `[TOC]`, or floating sidebar?
  • Slug algorithm: GitHub's exact rules (handles unicode, emoji, deduplication) vs the simpler default. Probably worth matching GitHub for consistency.

Constraints

  • No CDN dependencies. Slug logic is small enough to write in-tree.

Acceptance criteria

  • Every heading has a stable, unique `id`
  • Hovering a heading shows an anchor link
  • Clicking the anchor copies a sharable URL with `#slug`
  • (If TOC implemented) TOC links navigate correctly within the page

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions