JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5532745
  • Score
    100M100P100Q230322F
  • License MIT

Reparse a HAST tree

Package Exports

  • hast-util-raw

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hast-util-raw) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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 there’s 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 you’re 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