rehype plugin to parse the tree again (and raw nodes). Keeping positional info OK. 🙌
Tiny wrapper around
npm install rehype-raw
Say we have the following Markdown file,
<div class="note">A mix of *Markdown* and <em>HTML</em>.</div>
And our script,
example.js, looks as follows:
var vfile =var report =var unified =var markdown =var remark2rehype =var doc =var format =var stringify =var raw =
node example yields:
example.md: no issues found🙌A mix of Markdown and HTML.
Parse the tree again, also parsing “raw” nodes (as exposed by
This project parses a hast tree with embedded raw HTML.
This typically occurs because we’re coming from Markdown, often parsed by
Inside Markdown, HTML is a black box: Markdown doesn’t know what’s inside that
rehype-raw maps Markdown to HTML, it cannot understand raw embedded
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>.</div>
…this is seen as one big block of HTML:A mix of *Markdown* and HTML.
This does work:<div class="note">A mix of *Markdown* and <em>HTML</em>.</div>
…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:A mix of Markdown and HTML.
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:A mix of Markdown and HTML.
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
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.