Skip to content
plugin to transform from Markdown (remark) to HTML (rehype)
JavaScript
Branch: master
Clone or download
Latest commit 47e547d Jul 24, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig Update dev-dependencies Aug 28, 2016
.gitignore Add `yarn.lock` to `.gitignore` Aug 11, 2018
.npmrc Add `.npmrc` Aug 11, 2018
.prettierignore Refactor code-style Aug 11, 2018
.travis.yml Update Node in Travis Jun 17, 2019
index.js Refactor comments Jun 17, 2019
license Move `LICENSE` > `license` Nov 20, 2018
package.json Update dev-dependencies Jul 24, 2019
readme.md Add notes on security Jul 24, 2019
test.js Refactor code-style Aug 11, 2018

readme.md

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.

Install

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 script, example.js, looks as follows:

var vfile = require('to-vfile')
var report = require('vfile-reporter')
var unified = require('unified')
var markdown = require('remark-parse')
var remark2rehype = require('remark-rehype')
var doc = require('rehype-document')
var format = require('rehype-format')
var html = require('rehype-stringify')

unified()
  .use(markdown)
  .use(remark2rehype)
  .use(doc)
  .use(format)
  .use(html)
  .process(vfile.readSync('example.md'), function(err, file) {
    console.error(report(err || 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

origin.use(remark2rehype[, 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-react 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.

Related

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, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer

You can’t perform that action at this time.