Project: rehypejs/rehype-dom

Package: rehype-dom-stringify@3.0.0

  1. Dependents: 2
  2. rehype plugin to use browser APIs to stringify HTML
  1. unified 174
  2. html 121
  3. rehype 85
  4. tree 41
  5. ast 31
  6. syntax 27
  7. stringify 18
  8. compile 13
  9. abstract 10
  10. dom 9


Build Coverage Downloads Size Sponsors Backers Chat

rehype plugin to use browser APIs to stringify HTML. Compiler for unified. Used in the rehype-dom processor.

If you don’t care about bundle size, or if you don’t trust content, or if you’re not in a (modern) browser environment, use rehype-stringify instead.

As rehype-dom-stringify is designed for browser use, it defaults to parsing in fragment mode, whereas rehype-stringify defaults to document mode!


This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.


npm install rehype-dom-stringify


import {unified} from 'unified'
import rehypeDomParse from 'rehype-dom-parse'
import rehypeDomStringify from 'rehype-dom-stringify'

const processor = unified()
  .data('settings', {fragment: true})

processor.process('<p>text, <b>hyper').then((file) => {


<p>text, <b>hyper</b></p>


This package exports no identifiers. The default export is rehypeDomStringify.

unified().use(rehypeDomStringify[, options])

Configure a processor to take hast as input and stringify it to HTML.


Specify whether to stringify a fragment (boolean, default: true), instead of a complete document. In document mode, an html element is added to a fragment when needed.


Use of rehype-dom-stringify can open you up to a cross-site scripting (XSS) attack if the tree is unsafe. Use rehype-sanitize to make the tree safe.


See contributing.md in rehypejs/.github for ways to get started. See support.md for ways to get help.

This project has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.


ISC © Keith McKnight