unified

Project: remarkjs/remark-rehype

Package: remark-rehype@9.0.0

  1. Dependents: 230
  2. remark plugin to transform to rehype
  1. remark 190
  2. unified 174
  3. plugin 137
  4. markdown 131
  5. html 121
  6. rehype 85
  7. mdast 85
  8. remark-plugin 73
  9. hast 72
  10. rehype-plugin 60

remark-rehype

Build Coverage Downloads Size Sponsors Backers Chat

remark plugin to bridge or mutate to rehype.

Note: remark-rehype doesn’t deal with HTML inside the Markdown. You’ll need rehype-raw if you’re planning on doing that.

Note!

This plugin is ready for the new parser in remark (remarkjs/remark#536). The current and previous versions of the plugin work with the current and previous versions of remark.

Install

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

npm:

npm install remark-rehype

Use

Say we have the following file, example.md:

# Hello world

> Block quote.

Some _emphasis_, **importance**, and `code`.

And our module, example.js, looks as follows:

import {readSync} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeDocument from 'rehype-document'
import rehypeFormat from 'rehype-format'
import rehypeStringify from 'rehype-stringify'

const file = readSync('example.md')

unified()
  .use(remarkParse)
  .use(remarkRehype)
  .use(rehypeDocument)
  .use(rehypeFormat)
  .use(rehypeStringify)
  .process(file)
  .then((file) => {
    console.error(reporter(file))
    console.log(String(file))
  })

Now, running node example yields:

example.md: no issues found
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>example</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body>
    <h1>Hello world</h1>
    <blockquote>
      <p>Block quote.</p>
    </blockquote>
    <p>Some <em>emphasis</em>, <strong>importance</strong>, and <code>code</code>.</p>
  </body>
</html>

API

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

origin.use(remarkRehype[, destination][, options])

remark (mdast) plugin to bridge or mutate to rehype (hast).

destination

If a Unified processor is given, runs the destination processor with the new hast tree, then, after running discards that tree and continues on running the origin processor with the original tree (bridge mode). Otherwise, passes the tree to further plugins (mutate mode).

options

Passed to mdast-util-to-hast.

Security

Use of remark-rehype can open you up to a cross-site scripting (XSS) attack. Embedded hast properties (hName, hProperties, hChildren), custom handlers, and the allowDangerousHtml option all provide openings. Use rehype-sanitize to make the tree safe.

Contribute

See contributing.md in remarkjs/.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, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer