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

Go
58%
Apache 2.0

agent-orchestrator

AI Agents · AI Code Assistants · Developer Tools

13,536

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
87
Repo Health
83
Technical
67
Dependency
Built with
Go 58%
TypeScript 39%
Updated today
Rust
44%
MIT

Anarlog

AI Assistants · Note Taking · Productivity

9,565

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
65
Dependency
Built with
Rust 44%
TypeScript 41%
Updated today
Python
68%
Other

AutoGPT

AI Assistants · Automation · Productivity

187,722

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 68%
TypeScript 30%
Updated today
TypeScript
84%
Apache 2.0

Continue

AI Code Assistants · AI Development · Automation

36,303

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

View details
66
Repo Health
88
Technical
62
Dependency
Built with
TypeScript 84%
Updated 2 days ago
TypeScript
82%
MIT

evidence

Analytics · Data Engineering

7,052

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
91
Repo Health
79
Technical
64
Dependency
Built with
TypeScript 82%
Svelte 17%
Updated yesterday
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,235

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
74
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated today
TypeScript
63%
Apache 2.0

Laminar

AI Development · Monitoring

3,434

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
86
Repo Health
76
Technical
65
Dependency
Built with
TypeScript 63%
Rust 35%
Updated today
TypeScript
87%
MIT

medusa

Ecommerce

36,897

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

View details
94
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 87%
JavaScript 12%
Updated yesterday
TypeScript
82%
AGPL 3.0

OpenStatus

Devops · Monitoring

9,221

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 14%
Updated yesterday

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