# rehype-stringify [![Build][build-badge]][build] [![Coverage][coverage-badge]][coverage] [![Downloads][downloads-badge]][downloads] [![Size][size-badge]][size] [![Sponsors][sponsors-badge]][collective] [![Backers][backers-badge]][collective] [![Chat][chat-badge]][chat] [**rehype**][rehype] plugin to serialize HTML. [Compiler][] for [**unified**][unified]. Stringifies [**hast**][hast] syntax trees to HTML. Used in the [**rehype** processor][processor] but can be used on its own as well. If you’re in a browser, trust the content, and value a smaller bundle size, use [`rehype-dom-stringify`][rehype-dom-stringify] instead. ## Sponsors


🥇 ZEIT


🥇 Gatsby


🥇 Netlify


Holloway




You?
[**Read more about the unified collective on Medium »**][announcement] ## Install [npm][]: ```sh npm install rehype-stringify ``` ## Use ```js var unified = require('unified') var createStream = require('unified-stream') var parse = require('rehype-parse') var stringify = require('rehype-stringify') var processor = unified() .use(parse) .use(stringify, { quoteSmart: true, closeSelfClosing: true, omitOptionalTags: true, entities: {useShortestReferences: true} }) process.stdin.pipe(createStream(processor)).pipe(process.stdout) ``` ## API ### `processor.use(stringify[, options])` Configure `processor` to serialize [**hast**][hast] syntax trees to HTML. ###### `options` Options can be passed when using `processor.use(stringify, options)` or with `processor.data('settings', options)`. All settings are passed to [`hast-util-to-html`][hast-util-to-html]. ## Security As **rehype** works on HTML, and improper use of HTML can open you up to a [cross-site scripting (XSS)][xss] attack, use of rehype can also be unsafe. Use [`rehype-sanitize`][sanitize] to make the tree safe. ## Contribute See [`contributing.md`][contributing] in [`rehypejs/.github`][health] for ways to get started. See [`support.md`][support] for ways to get help. Ideas for new plugins and tools can be posted in [`rehypejs/ideas`][ideas]. A curated list of awesome rehype resources can be found in [**awesome rehype**][awesome]. This project has a [code of conduct][coc]. By interacting with this repository, organization, or community you agree to abide by its terms. ## License [MIT][license] © [Titus Wormer][author] [build-badge]: https://img.shields.io/travis/rehypejs/rehype.svg [build]: https://travis-ci.org/rehypejs/rehype [coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype.svg [coverage]: https://codecov.io/github/rehypejs/rehype [downloads-badge]: https://img.shields.io/npm/dm/rehype-stringify.svg [downloads]: https://www.npmjs.com/package/rehype-stringify [size-badge]: https://img.shields.io/bundlephobia/minzip/rehype-stringify.svg [size]: https://bundlephobia.com/result?p=rehype-stringify [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg [backers-badge]: https://opencollective.com/unified/backers/badge.svg [collective]: https://opencollective.com/unified [chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg [chat]: https://spectrum.chat/unified/rehype [health]: https://github.com/rehypejs/.github [contributing]: https://github.com/rehypejs/.github/blob/master/contributing.md [support]: https://github.com/rehypejs/.github/blob/master/support.md [coc]: https://github.com/rehypejs/.github/blob/master/code-of-conduct.md [ideas]: https://github.com/rehypejs/ideas [awesome]: https://github.com/rehypejs/awesome-rehype [license]: https://github.com/rehypejs/rehype/blob/master/license [author]: https://wooorm.com [npm]: https://docs.npmjs.com/cli/install [unified]: https://github.com/unifiedjs/unified [rehype]: https://github.com/rehypejs/rehype [processor]: https://github.com/rehypejs/rehype/tree/master/packages/rehype [compiler]: https://github.com/unifiedjs/unified#processorcompiler [hast]: https://github.com/syntax-tree/hast [hast-util-to-html]: https://github.com/syntax-tree/hast-util-to-html#tohtmlnode-options [rehype-dom-stringify]: https://github.com/rehypejs/rehype-dom/tree/master/packages/rehype-dom-stringify [announcement]: https://medium.com/unifiedjs/collectively-evolving-through-crowdsourcing-22c359ea95cc [sanitize]: https://github.com/rehypejs/rehype-sanitize [xss]: https://en.wikipedia.org/wiki/Cross-site_scripting