Files
30-seconds-of-code/node_modules/hast-util-raw

hast-util-raw Build Status Coverage Status

Parse a HAST tree again, with support for embedded raw nodes.

One of the reasons to do this is for “malformed” syntax trees: for example, say theres an h1 element in a p element, this utility will make them siblings.

Another reason to do this is if raw HTML/XML is embedded in a syntax tree, such as markdown. If youre working with markdown, use remark-rehype and rehype-raw.

Installation

npm:

npm install hast-util-raw

Usage

var h = require('hastscript')
var raw = require('hast-util-raw')

var tree = h('div', [h('h1', ['Foo ', h('h2', 'Bar'), ' Baz'])])

var clean = raw(tree)

console.log(clean)

Yields:

{ type: 'element',
  tagName: 'div',
  properties: {},
  children:
   [ { type: 'element',
       tagName: 'h1',
       properties: {},
       children: [Object] },
     { type: 'element',
       tagName: 'h2',
       properties: {},
       children: [Object] },
     { type: 'text', value: ' Baz' } ] }

API

raw(tree[, file])

Given a HAST tree and an optional vfile (for positional info), return a new parsed-again HAST tree.

Contribute

See contributing.md in syntax-tree/hast for ways to get started.

This organisation has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer