rehype transforms HTML through plugins that read and modify a syntax tree. It parses HTML to hast, runs plugins, and stringifies back to HTML on servers, clients, or CLIs.
Overview
rehype is a JavaScript tool for processing HTML as structured data via abstract syntax trees. Plugins inspect and mutate the tree, enabling format changes, linting, sanitization, and other HTML workflows in the unified content pipeline.
The monorepo bundles parsers and stringifiers: rehype-parse turns HTML into a hast tree, rehype-stringify renders trees back to HTML, and the main rehype package wires both when input and output are HTML. rehype-cli formats and inspects HTML files from the command line in projects.
rehype sits on unified, which handles generic AST transformation, and hast defines the HTML tree shape. A large plugin ecosystem extends behavior; third-party plugin quality should be evaluated, and rehype-sanitize helps when XSS safety matters.
It runs on maintained Node.js versions, ships TypeScript types, and supports server, client, CLI, and Deno environments.
Key features
- HTML to hast syntax trees
- Plugin pipeline transformations
- Bundled parse and stringify
- rehype-cli for project HTML
- TypeScript typings
- unified ecosystem integration
- Large third-party plugin catalog
- Sanitization via companion plugins
Use cases
- HTML formatting in repos
- Static site HTML post-processing
- Unified markdown-to-HTML chains
- Linting or normalizing markup
- Custom HTML AST transforms