rehype

A unified-based HTML processor with a large plugin ecosystem

Library
npm
v13.0.2
2,247stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
58/100Fair
Development Activity36
Maintenance44
Community52
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
76/100Good
Architecture80
Code Quality78
Innovation70
Learning Curve75

rehype is a unified processor preconfigured with rehype-parse and rehype-stringify, giving you a ready-to-use pipeline for parsing HTML into a HAST syntax tree, running plugins to transform it, and serializing it back to HTML. It is a shortcut for unified().use(rehypeParse).use(rehypeStringify), part of the broader unifiedjs collective alongside remark (Markdown) and retext (prose).

As a monorepo, it also houses rehype-parse, rehype-stringify, and rehype-cli, and anchors a large third-party plugin ecosystem used for HTML linting, sanitization, minification, and static-site content transformation.

What You Get

  • A preconfigured unified processor combining rehype-parse and rehype-stringify
  • A HAST (HTML AST) syntax tree representation for programmatic HTML manipulation
  • Compatibility with the large ecosystem of rehype plugins (sanitize, minify, highlight, etc.)
  • TypeScript types for the processor and its syntax tree
  • A companion rehype-cli package for command-line HTML linting/formatting
  • Interop with remark (Markdown) via remark-rehype for Markdown-to-HTML pipelines

Common Use Cases

  • Transforming HTML content in static site generators (adding IDs to headings, autolinking, etc.)
  • Sanitizing untrusted HTML before rendering it in a web app
  • Linting and auto-formatting HTML files from the command line via rehype-cli
  • Building a Markdown-to-HTML pipeline together with remark and remark-rehype
  • Extracting or rewriting structured data from HTML documents programmatically

Under The Hood

Architecture - The root packages/rehype/index.js composes three sibling packages in the same monorepo: rehype-parse (HTML string to HAST tree), the unified engine (which runs registered plugins over the tree), and rehype-stringify (HAST tree back to an HTML string); rehype-cli sits alongside as a separate consumer of the same processor for command-line use, and the whole ecosystem interops with remark/retext via shared unist-family syntax trees.

Tech Stack - Pure ESM JavaScript ("type": "module") with hand-written .d.ts type declarations, managed as an npm/yarn workspaces monorepo (packages/rehype-parse, packages/rehype-stringify, packages/rehype, packages/rehype-cli), using c8 for coverage, remark-preset-wooorm for internal doc linting, and type-coverage to enforce TypeScript type completeness across the packages.

Code Quality - The monorepo has an extensive test/ directory with parse-error fixtures and syntax-tree assertions via hast-util-assert, plus CI workflows under .github/workflows; the actual rehype package itself is intentionally tiny (a ~10-line index.js), so most complexity and testing responsibility lives in the rehype-parse/rehype-stringify/unified dependencies it composes.

API Design - The processor exposes exactly the unified API (.use(), .process(), .processSync(), .parse(), .stringify()), so anyone familiar with unified/remark can use rehype immediately with zero new concepts to learn; the README explicitly steers users toward using unified directly when they don’t need both parse and stringify, favoring composability over a bespoke convenience API.

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