rehype-dom
unified processor to use browser APIs to parse and compile HTML.
- Interface by unified
- hast syntax tree
- Parses HTML to the tree with rehype-dom-parse
- Plug-ins transform the tree
- Compiles the tree to HTML using rehype-dom-stringify
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.