Install Rehype

rehype runs on Node.js and is installed with a package manager. Choose the option that matches what you want to do.

Requirements

  • Node.js. The rehype readme says the current release line is kept compatible with Node.js 16 and later, and that unified projects support maintained Node.js versions. Use a current LTS release of Node.js; the examples on this site were run with Node.js 22.
  • A package manager. npm ships with Node.js. pnpm, Yarn and Bun can install the same packages.
  • ES modules. rehype and its plugins are ESM only. Use import in .mjs files or set "type": "module" in package.json.

Check what you have:

Terminal
node --version
npm --version

Quick start

Terminal
mkdir rehype-demo && cd rehype-demo
npm init -y
npm pkg set type=module
npm install rehype rehype-format

Save this as example.js and run node example.js:

example.js
import {rehype} from 'rehype'
import rehypeFormat from 'rehype-format'

const input = `<!doctype html><html lang=en><head><title>Demo</title></head>
<body><main><h1>Hello</h1><p>Formatted by <b>rehype</b>.</p></main></body></html>`

const file = await rehype().use(rehypeFormat).process(input)

console.log(String(file))
Output Output
<!doctype html>
<html lang="en">
  <head>
    <title>Demo</title>
  </head>
  <body>
    <main>
      <h1>Hello</h1>
      <p>Formatted by <b>rehype</b>.</p>
    </main>
  </body>
</html>

Which package do I need?

PackageContainsInstall when
rehypeunified + rehype-parse + rehype-stringifyHTML in, HTML out (the common case)
rehype-parseHTML parser pluginHTML in, something else out (for example Markdown)
rehype-stringifyHTML serializer pluginSomething else in (for example Markdown via remark), HTML out
rehype-cliThe rehype commandWorking with files from a terminal

Not sure what the source code download is for? See Download Rehype.

Use ↑ ↓ to move, Enter to open.