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
267stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
38/100Needs Attention
Development Activity0
Maintenance20
Community52
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
66/100Good
Architecture72
Code Quality88
Innovation45
Learning Curve60

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 10 apps in this directory

TypeScript
53%
MIT

Anarlog

Note Taking · AI Assistants · Productivity

9,252

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
TypeScript53%
Rust35%
Updated today
Python
67%
Other

AutoGPT

Automation · Productivity · AI Assistants

187,177

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
Python67%
TypeScript32%
Updated today
TypeScript
84%
Apache 2.0

Continue

Developer Tools · AI Development · AI Code Assistants

35,808

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

View details
81
Repo Health
88
Technical
62
Dependency
Built with
TypeScript84%
Updated yesterday
TypeScript
82%
MIT

evidence

Analytics · Data Engineering

6,911

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
87
Repo Health
79
Technical
64
Dependency
Built with
TypeScript82%
Svelte18%
Updated 3 days ago
TypeScript
91%
Apache 2.0

Helicone

Monitoring · AI Development · Analytics

6,133

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
69
Repo Health
81
Technical
65
Dependency
Built with
TypeScript91%
Updated 1 weeks ago
TypeScript
81%
AGPL 3.0

OpenStatus

Monitoring · Devops

9,072

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
TypeScript81%
MDX15%
Updated yesterday
TypeScript
75%
MIT

OpenCode

AI Code Assistants

205,271

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
66
Dependency
Built with
TypeScript75%
MDX21%
Updated today
TypeScript
98%
AGPL 3.0

paseo

AI Agents · AI Code Assistants

16,216

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

View details
87
Repo Health
83
Technical
68
Dependency
Built with
TypeScript98%
Updated yesterday
TypeScript
71%
Apache 2.0

Supabase

Developer Tools · Databases · Search

108,912

The open-source Postgres development platform that replaces Firebase with authentication, real-time APIs, edge functions, storage, and vector embeddings — all built on PostgreSQL.

View details
90
Repo Health
91
Technical
62
Dependency
Built with
TypeScript71%
MDX26%
Updated today

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

Search