rehype-slug

Rehype plugin that adds GitHub-style id attributes to HTML headings for anchor links.

Library
npm
v6.0.0
264stars
MIT License

Repository Health

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

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture78
Code Quality88
Innovation85
Learning Curve35

rehype-slug is a plugin for the unified/rehype ecosystem that automatically adds id attributes to HTML headings (h1 through h6) that don’t already have one. It generates each id from the heading’s text content using the same slugging algorithm GitHub uses on its own rendered markdown, via the github-slugger dependency, so anchors line up with how GitHub displays the same content.

The plugin operates directly on the hast (HTML AST) tree produced by rehype, visiting every element node and checking whether it’s a heading lacking an id. It’s commonly paired with rehype-autolink-headings, which adds clickable anchor links back to the ids this plugin creates — together they power the “click to copy link” heading UX found on many documentation sites and markdown-to-HTML pipelines, including MDX-based static site generators.

What You Get

  • Automatic id generation for every heading level (h1-h6) that lacks one
  • GitHub-compatible slugs via the github-slugger dependency, so anchors match GitHub-rendered markdown
  • An optional prefix option to namespace generated ids
  • Full TypeScript types shipped with the package, with no separate @types install needed

Common Use Cases

  • Adding deep-linkable anchors to long-form documentation pages
  • Powering “copy link to heading” UI in docs sites and blogs
  • Building a table of contents that links to in-page headings
  • Ensuring markdown-rendered headings get consistent, predictable ids across a site

Under The Hood

Architecture rehype-slug is a single-file plugin (lib/index.js) exporting a default factory function that returns a unified transformer. The transformer walks the hast tree with unist-util-visit, uses hast-util-heading-rank to detect heading elements and hast-util-to-string to extract their text, then assigns ids through a module-scoped GithubSlugger instance that gets reset at the start of every run. There’s no internal layering beyond this — the interesting architecture lives in the small set of well-established unified-ecosystem utilities it composes rather than in custom abstractions of its own. The shared, reset-per-run slugger instance is a minor design note worth flagging for anyone processing multiple files concurrently in the same process.

Tech Stack Dependencies are exclusively other unified/rehype/hast ecosystem packages (github-slugger, hast-util-heading-rank, hast-util-to-string, unist-util-visit, plus @types/hast), and the package is published as ESM-only ("type": "module"). Source is plain JavaScript annotated with JSDoc types rather than compiled TypeScript; tsc --build is used only to emit declaration files and check types, not to transpile the runtime code. Tooling is xo (an ESLint preset) with Prettier for style, remark-cli with remark-preset-wooorm for linting the README itself, type-coverage to enforce fully-typed JSDoc, and c8 for coverage — no bundler is needed since it ships as a tiny, dependency-thin ESM module.

Code Quality Tests live in a single test.js run via Node’s built-in test runner (node:test), covering the public API shape, default heading-id behavior, and the prefix option, with c8 --100 --check-coverage enforcing full statement coverage as part of the test script. Type safety is enforced strictly through type-coverage at 100%, and xo/Prettier keep style consistent. CI workflow files aren’t visible in a shallow clone, but README badges reference an active GitHub Actions build and Codecov coverage tracking. Between full coverage enforcement, strict typing, and consistent linting, code quality is comprehensive for a package this size.

API Design The public API is a single default export with zero required configuration — .use(rehypeSlug) works immediately — and exactly one optional prefix string for namespacing. Types ship alongside the runtime code so consumers get editor autocomplete and type-checking without installing a separate @types package. Naming and usage conventions match sibling unified plugins (rehype-*, remark-*), so anyone already using the ecosystem has effectively no onboarding cost.

Used by 14 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
65%
Apache 2.0

Laminar

AI Development · Monitoring

3,230

Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.

View details
85
Repo Health
76
Technical
69
Dependency
Built with
TypeScript65%
Rust33%
Updated yesterday
TypeScript
86%
MIT

medusa

Ecommerce

36,163

The most flexible open-source commerce platform — build B2C, B2B, and marketplace applications with modular, composable commerce primitives.

View details
93
Repo Health
87
Technical
63
Dependency
Built with
TypeScript86%
JavaScript14%
Updated 2 days 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
Vue
41%
AGPL 3.0

Operational

Analytics · Automation · Monitoring

476

Open-source event tracker with real-time push notifications and action buttons for tech founders.

View details
54
Repo Health
68
Technical
71
Dependency
Built with
Vue41%
JavaScript38%
MDX13%
Updated 1 months 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

Search