rehype-autolink-headings

Rehype plugin that injects clickable anchor links into every heading with an id, so readers can share direct links to a section.

Library
npm
v7.1.0
267 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
38 /100 Needs Attention
Development Activity 0
Maintenance 20
Community 52
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
66 /100 Good
Architecture 72
Code Quality 88
Innovation 45
Learning Curve 60

rehype-autolink-headings is a plugin for the unified/rehype content-transformation ecosystem that walks an HTML abstract syntax tree (hast) and adds a self-referencing link to every heading element that already has an id property. It looks for <h1> through <h6> elements, and for each one inserts an <a href="#id"> pointing back at itself, the same pattern used to generate the clickable heading anchors seen on GitHub and npm when rendering markdown.

The plugin is deliberately narrow in scope — it only links headings that already have ids, and is almost always paired with rehype-slug (which generates those ids from heading text) in a single unified pipeline. Its configuration surface covers five distinct link-placement behaviors (prepend, append, wrap, before, after), fully custom link/wrapper content via static hast nodes or a builder function, and fine-grained control over which headings qualify via a hast-util-is-element-compatible test.

What You Get

  • A single default-exported plugin function you register with unified().use() in a rehype pipeline
  • Five link-placement behaviors (prepend, append, wrap, before, after) selectable via one option
  • Full control over injected link/wrapper content, either as static hast nodes or a per-heading builder function
  • A test option (any hast-util-is-element test) to restrict which headings get linked, e.g. skip <h1>
  • Full TypeScript types for Options, Behavior, Build, and BuildProperties, published alongside the JS

Common Use Cases

  • Documentation sites piping content through rehype/remark add it after rehype-slug so every section heading becomes a shareable deep link
  • MDX-based blogs and content platforms use it to give generated tables of contents working in-page anchors
  • Teams wanting a link icon instead of plain text pass a content builder function (often built with hastscript) to render an SVG/icon span inside the anchor
  • API-reference and structured-docs generators use it so every rendered heading (method, class, section) is individually linkable for cross-referencing

Under The Hood

Architecture The entire plugin lives in a single module, lib/index.js: rehypeAutolinkHeadings(options) runs once at pipeline-setup time to resolve configuration (behavior, content, group, test) and pick one of three visitor strategies — inject (prepend/append), around (before/after, with optional group wrapping), or wrap — then returns a transform that walks the hast tree once with unist-util-visit, matching elements via hast-util-heading-rank (is this a heading?) plus a required id property and the optional custom test. The design is a clean, single-responsibility functional module with no classes or internal layering — appropriate for its narrow scope, though it means all matching, dispatch, and node-construction logic sits in one file rather than being decomposed further.

Tech Stack An ESM-only (type: module) package with a small, ecosystem-native dependency set: @types/hast (types only), @ungap/structured-clone (a deep-clone polyfill used when copying user-supplied content/group nodes), hast-util-heading-rank, hast-util-is-element, and unist-util-visit — all standard unified-project building blocks. There’s no separate compiled build step for the JS itself; types are authored via JSDoc and checked against a hand-written lib/types.d.ts using tsc plus type-coverage (configured to require 100% coverage). Linting/formatting run through xo (ESLint) and prettier, with remark-preset-wooorm for markdown-doc formatting.

Code Quality Tests live in test/index.js using Node’s built-in node:test and node:assert, combining direct API-behavior assertions (custom content/group/properties/headingProperties functions) with a data-driven fixture suite — 14 fixture folders under test/fixtures/, each an input.html/output.html/optional config.json triple covering every behavior and option combination. Coverage is enforced via c8 --100 --check-coverage, and CI (.github/workflows/main.yml) runs the full test suite across two Node LTS versions with Codecov reporting. Combined with the 100%-required type-coverage check, this is a well-tested, strictly-typed small package.

What Makes It Unique The plugin isn’t algorithmically novel — it’s a straightforward, single-pass AST transform — but it functions as the de facto standard solution within the unified/rehype ecosystem for heading-anchor links, designed to compose cleanly with rehype-slug and any other rehype/remark plugin in a pipeline. Its value is in the completeness of its configuration surface (five behaviors, arbitrary custom content/grouping, selective heading targeting) rather than in a new technique.

Used by 11 apps in this directory

Go
59%
Apache 2.0

agent-orchestrator

AI Agents · AI Code Assistants · Developer Tools

12,440

A local desktop workspace that gives every coding task its own agent, Git branch, and worktree, then tracks tasks, pull requests, CI, and reviews for 27 coding agents on one live Kanban board.

View details
86
Repo Health
83
Technical
68
Dependency
Built with
Go 59%
TypeScript 38%
Updated 1 weeks ago
TypeScript
54%
MIT

Anarlog

AI Assistants · Note Taking · Productivity

9,404

Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.

View details
86
Repo Health
77
Technical
68
Dependency
Built with
TypeScript 54%
Rust 34%
Updated 1 weeks ago
Python
66%
Other

AutoGPT

AI Assistants · Automation · Productivity

187,596

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
66
Dependency
Built with
Python 66%
TypeScript 33%
Updated 1 weeks ago
TypeScript
84%
Apache 2.0

Continue

AI Code Assistants · AI Development · Automation

36,049

Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.

View details
73
Repo Health
88
Technical
62
Dependency
Built with
TypeScript 84%
Updated 1 weeks ago
TypeScript
82%
MIT

evidence

Analytics · Data Engineering

6,962

Turn SQL queries and markdown files into polished, interactive data apps and business intelligence reports — no drag-and-drop, no GUI, just code.

View details
90
Repo Health
79
Technical
64
Dependency
Built with
TypeScript 82%
Svelte 17%
Updated 2 weeks ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 3 weeks ago
TypeScript
82%
AGPL 3.0

OpenStatus

Devops · Monitoring

9,143

Open-source status pages and uptime monitoring with global synthetic checks, monitoring-as-code, and AI agent integration via MCP.

View details
77
Repo Health
82
Technical
69
Dependency
Built with
TypeScript 82%
MDX 15%
Updated 1 weeks ago
TypeScript
75%
MIT

OpenCode

AI Code Assistants

210,460

A fully open-source AI coding agent built for the terminal, with a TUI, desktop app, web client, plugin system, and SDK — one of the most-starred AI coding agents on GitHub.

View details
89
Repo Health
76
Technical
67
Dependency
Built with
TypeScript 75%
MDX 22%
Updated 1 weeks ago
TypeScript
98%
AGPL 3.0

paseo

AI Agents · AI Code Assistants

18,731

One unified interface to orchestrate Claude Code, Codex, Copilot, OpenCode, and Pi agents in parallel from desktop, mobile, or the terminal.

View details
88
Repo Health
83
Technical
69
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers