0.10.0 • Published 5 years ago
@starptech/hast-util-from-webparser v0.10.0
@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.
0.10.0
5 years ago
0.9.0
5 years ago
0.8.17
5 years ago
0.8.10
5 years ago
0.8.7
5 years ago
0.8.6
5 years ago
0.8.5
5 years ago
0.8.3
5 years ago
0.8.1
5 years ago
0.8.0
5 years ago
0.7.0
5 years ago
0.6.0
5 years ago
0.5.3
5 years ago
0.5.2
5 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