Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

rehype-dom

4.0.0 • Public • Published

rehype-dom

Build Coverage Downloads Size Sponsors Backers Chat

unified processor to use browser APIs to parse and compile HTML.

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 instead.

If you’re not concerned with bundle size or are in an environment in which you don’t trust (or don’t have) the native DOM API, you may prefer to use rehype instead.

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

Don’t need the parser? Or the compiler? That’s OK.

Install

yarn:

yarn add rehype-dom

npm:

npm install rehype-dom

Use

import unified from 'unified';
import createStream from 'unified-stream';
import rehypeDom from 'rehype-dom';
 
rehypeDom().process('<p>text, <b>hyper', (err, file) => {
  if (err) {
    console.error(err);
  } else {
    console.log(String(file));
  }
});

Yields:

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

Configuration for rehype-dom-parse and rehype-dom-stringify can be set with .data('settings', {/*...*/}).

Security

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

Contribute

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.

License

ISC © Keith McKnight

Install

npm i rehype-dom

DownloadsWeekly Downloads

39

Version

4.0.0

License

ISC

Unpacked Size

6.01 kB

Total Files

4

Last publish

Collaborators

  • avatar
  • avatar