@starptech/hast-util-from-webparser
Produce [HAST](https://github.com/syntax-tree/hast) compatible AST from [Webparser](https://github.com/Prettyhtml/prettyhtml/tree/master/packages/webparser)
Last updated 6 years ago by starptech .
ISC · Original npm · Tarball · package.json
$ gnpm install @starptech/hast-util-from-webparser 
SYNC missed versions from official npm registry.

@starptech/hast-util-from-webparser

Produce HAST compatible AST from Webparser

Installation

@starptech/hast-util-from-webparser

Usage

Say we have the following file, example.html:

<!DOCTYPE html><title>Hello!</title>
<h1 id="world">World!<!--after--></h1>

And our script, example.js, looks as follows:

const vfile = require('to-vfile')
const inspect = require('unist-util-inspect')
const HtmlParser = require('@starptech/webparser').HtmlParser
const fromWebparser = require('@starptech/hast-util-from-webparser')

const filepath = 'example.html'
const doc = vfile.readSync(filepath)
const result = new HtmlParser({
  ignoreFirstLf: false,
  decodeEntities: false,
  selfClosingCustomElements: true
}).parse(String(doc), filepath)

const hast = fromWebparser(result.rootNodes)

Now, running node example yields:

root[3] [data={"selfClosing":false}]
├─ doctype (1:1-1:15, 0-15) [name="html"]
├─ element[1] (1:15-1:36, 15-36) [tagName="title"][data={"selfClosing":false}]
│  └─ text: "Hello!" (1:22-1:28, 22-28)
└─ element[2] [tagName="h1"][properties={"id":"world"}][data={"selfClosing":false}]
   ├─ text: "World!" (1:51-1:57, 51-57)
   └─ comment: "after" (1:57-1:61, 57-61)

API

fromWebparser(rootNodes[, options])

Transform an Node to a HAST Node.

Current Tags

  • 0.10.0                                ...           latest (5 years ago)

34 Versions

  • 0.10.0                                ...           5 years ago
  • 0.9.0                                ...           6 years ago
  • 0.8.17                                ...           6 years ago
  • 0.8.10                                ...           6 years ago
  • 0.8.7                                ...           6 years ago
  • 0.8.6                                ...           6 years ago
  • 0.8.5                                ...           6 years ago
  • 0.8.3                                ...           6 years ago
  • 0.8.1                                ...           6 years ago
  • 0.8.0                                ...           6 years ago
  • 0.7.0                                ...           6 years ago
  • 0.6.0                                ...           6 years ago
  • 0.5.3                                ...           6 years ago
  • 0.5.2                                ...           6 years ago
  • 0.5.0                                ...           6 years ago
  • 0.4.2                                ...           6 years ago
  • 0.4.1                                ...           6 years ago
  • 0.4.0                                ...           6 years ago
  • 0.3.4                                ...           6 years ago
  • 0.3.2                                ...           6 years ago
  • 0.3.1                                ...           6 years ago
  • 0.3.0                                ...           6 years ago
  • 0.2.4                                ...           6 years ago
  • 0.2.3                                ...           6 years ago
  • 0.2.2                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.9                                ...           6 years ago
  • 0.1.8                                ...           6 years ago
  • 0.1.7                                ...           6 years ago
  • 0.1.5                                ...           6 years ago
  • 0.1.4                                ...           6 years ago
  • 0.1.2                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dev Dependencies (7)

Copyright 2013 - present © cnpmjs.org | Home |