rehype-raw

WebJar for rehype-raw

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

rehype-raw
Last Version

Last Version

4.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

rehype-raw
WebJar for rehype-raw
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/rehypejs/rehype-raw

Download rehype-raw

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/rehype-raw/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>rehype-raw</artifactId>
    <version>4.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/rehype-raw/
implementation 'org.webjars.npm:rehype-raw:4.0.2'
// https://jarcasting.com/artifacts/org.webjars.npm/rehype-raw/
implementation ("org.webjars.npm:rehype-raw:4.0.2")
'org.webjars.npm:rehype-raw:jar:4.0.2'
<dependency org="org.webjars.npm" name="rehype-raw" rev="4.0.2">
  <artifact name="rehype-raw" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='rehype-raw', version='4.0.2')
)
libraryDependencies += "org.webjars.npm" % "rehype-raw" % "4.0.2"
[org.webjars.npm/rehype-raw "4.0.2"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm » hast-util-raw jar [5.0.0,6)

Project Modules

There are no modules declared in this project.

rehype-raw

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

Install

npm:

npm install rehype-raw

Use

Say we have the following Markdown file, example.md:

<div class="note">

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

</div>

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')

unified()
  .use(markdown)
  .use(remark2rehype, {allowDangerousHtml: true})
  .use(raw)
  .use(doc, {title: '🙌'})
  .use(format)
  .use(stringify)
  .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>🙌</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body>
    <div class="note">
      <p>A mix of <em>Markdown</em> and <em>HTML</em>.</p>
    </div>
  </body>
</html>

API

rehype().use(raw)

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

Note

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>.
    </div>

    …this is seen as one big block of HTML:

    <div class="note">
    A mix of *Markdown* and <em>HTML</em>.
    <div>
  • 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:

    <div class="note">
    A mix of <em>Markdown</em> and <em>HTML</em>.
    <div>
  • 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.

Security

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.

Contribute

See contributing.md in rehypejs/.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

org.webjars.npm

rehype

HTML processor powered by plugins part of the @unifiedjs collective

Versions

Version
4.0.2