rehype-remark

Converts an HTML tree (hast) into a Markdown tree (mdast), the bridge from rehype to remark.

Category
Interop
Maintained by
rehype team
License
MIT
Module format
ESM, default export
Install
npm install rehype-remark

What it does

rehype-remark transforms hast into mdast using hast-util-to-mdast. Plugins used after it are remark plugins, and remark-stringify turns the result into Markdown text.

Example

html-to-markdown.mjs
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
import rehypeRemark from 'rehype-remark'
import remarkStringify from 'remark-stringify'

const html = `<h2>Changelog</h2>
<p>Fixed <strong>two</strong> bugs. See <a href="https://github.com/rehypejs/rehype">the repo</a>.</p>
<ul><li>Parser</li><li>CLI</li></ul>`

const file = await unified()
  .use(rehypeParse)
  .use(rehypeRemark)
  .use(remarkStringify)
  .process(html)

console.log(String(file))
Output node html-to-markdown.mjs
## Changelog

Fixed **two** bugs. See [the repo](https://github.com/rehypejs/rehype).

* Parser
* CLI

remark-stringify uses * for bullets by default; pass {bullet: '-'} to it if you prefer dashes. Add remark-gfm after rehype-remark to write tables, strikethrough and task lists.

Options

  • document (default true): whether the input is a complete document; affects paragraph wrapping.
  • newlines (default false): keep line endings when collapsing whitespace.
  • checked (default '[x]') and quotes: how checkboxes and <q> elements are written.
  • handlers and nodeHandlers: custom conversion for specific elements, merged into the defaults.

Limits

Markdown has no syntax for many HTML features (classes, layout elements, merged table cells, forms), so those are dropped or simplified. Review converted content before publishing it. Try conversions instantly in the HTML to Markdown converter.

Official references

Facts on this page were checked against the package readme on November 11, 2026. Options not covered here are documented upstream.

Use ↑ ↓ to move, Enter to open.