rehype-slug

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

Library
npm
v6.0.0
264 stars
MIT License

Repository Health

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

Technical Analysis

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

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

Vue
41%
AGPL 3.0

Operational

Analytics · Automation · Monitoring

474

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

View details
54
Repo Health
68
Technical
68
Dependency
Built with
Vue 41%
JavaScript 39%
MDX 13%
Updated 3 weeks ago
TypeScript
96%
MIT

Orca

AI Agents · AI Code Assistants

104,104

An open-source Agent Development Environment that orchestrates fleets of parallel AI coding agents — Claude Code, Codex, Gemini and more — each running in its own isolated git worktree.

View details
84
Repo Health
85
Technical
74
Dependency
Built with
TypeScript 96%
Updated 5 days ago
TypeScript
98%
AGPL 3.0

paseo

AI Agents · AI Code Assistants

21,830

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
66
Dependency
Built with
TypeScript 98%
Updated 5 days ago
Python
62%
Apache 2.0

Polar

Developer Tools · Ecommerce · Invoicing Finance

10,410

Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.

View details
90
Repo Health
82
Technical
66
Dependency
Built with
Python 62%
TypeScript 31%
Updated 6 days ago
TypeScript
72%
Apache 2.0

Supabase

Authentication · Databases · Developer Tools

113,827

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
TypeScript 72%
MDX 26%
Updated 5 days ago
TypeScript
65%
Other

Typebot

AI Assistants · AI Development · Developer Tools

10,576

Build sophisticated chatbots visually, embed them anywhere without iframes, and own your data — fully self-hostable with a modular block system and 30+ integrations.

View details
94
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 65%
MDX 34%
Updated 6 days 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