rehype plugin to reparse the tree (and raw nodes)
Last updated 4 months ago by wooorm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install rehype-raw 
SYNC missed versions from official npm registry.


Build Coverage Downloads Size Sponsors Backers Chat

rehype plugin to parse the tree again (and raw nodes). Keeping positional info OK. ????

Tiny wrapper around hast-util-raw



npm install rehype-raw


Say we have the following Markdown file,

<div class="note">

A mix of *Markdown* and <em>HTML</em>.


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 stringify = require('rehype-stringify')
var raw = require('rehype-raw')

  .use(remark2rehype, {allowDangerousHTML: true})
  .use(doc, {title: '????'})
  .process(vfile.readSync(''), function(err, file) {
    console.error(report(err || file))

Now, running node example yields: no issues found
<!doctype html>
<html lang="en">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <div class="note">
      <p>A mix of <em>Markdown</em> and <em>HTML</em>.</p>



Parse the tree again, also parsing “raw” nodes (as exposed by remark-rehype).


This project parses a hast tree with embedded raw HTML. This typically occurs because we’re coming from Markdown, often parsed by remark-parse. Inside Markdown, HTML is a black box: Markdown doesn’t know what’s inside that HTML. So, when rehype-raw maps Markdown to HTML, it cannot understand raw embedded HTML.

That’s where this project comes in.

But, Markdown is much terser than HTML, so it’s often preferred to use Markdown, in HTML, inside Markdown. As can be seen in the above example.

However, Markdown can only be mixed with HTML in some cases. Take the following examples:

  • Warning: does not work:

    <div class="note">
    A mix of *Markdown* and <em>HTML</em>.

    …this is seen as one big block of HTML:

    <div class="note">
    A mix of *Markdown* and <em>HTML</em>.
  • This does work:

    <div class="note">
    A mix of *Markdown* and <em>HTML</em>.

    …it’s one block with the opening HTML tag, then a paragraph of Markdown, and another block with closing HTML tag. That’s because of the blank lines:

    <div class="note">
    A mix of <em>Markdown</em> and <em>HTML</em>.
  • This also works:

    <span class="note">A mix of *Markdown* and <em>HTML</em>.</span>

    …Inline tags are parsed as separate tags, with Markdown in between:

    <p><span class="note">A mix of <em>Markdown</em> and <em>HTML</em>.</span></p>

    This occurs if the tag name is not included in the list of block tag names.


Improper use of rehype-raw can open you up to a cross-site scripting (XSS) attack.

Either do not combine this plugin with user content or use rehype-sanitize.


See in rehypejs/.github for ways to get started. See 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.


MIT © Titus Wormer

Current Tags

  • 4.0.2                                ...           latest (4 months ago)

6 Versions

  • 4.0.2                                ...           4 months ago
  • 4.0.1                                ...           a year ago
  • 4.0.0                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.0.0                                ...           3 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (2)
Today 5
This Week 5
This Month 335
Last Day 17
Last Week 225
Last Month 563
Dependencies (1)
Dev Dependencies (12)

Copyright 2014 - 2016 © |