@@ -12,46 +12,41 @@ npm install hast-util-from-parse5
1212
1313## Usage
1414
15- Dependencies :
15+ Say we have the following file, ` example.html ` :
1616
17- ``` javascript
18- var parse5 = require (' parse5' );
19- var inspect = require (' unist-util-inspect' );
20- var vfile = require (' vfile' );
21- var fromParse5 = require (' hast-util-from-parse5' );
22- ```
23-
24- Fixture:
25-
26- ``` javascript
27- var doc = ' <!doctype html><title>Hello!</title><h1 id="world">World!<!--after-->' ;
17+ ``` html
18+ <!doctype html><title >Hello!</title ><h1 id =" world" >World!<!-- after-->
2819```
2920
30- Parse :
21+ And our script, ` example.js ` , looks as follows :
3122
3223``` javascript
33- var ast = parse5 .parse (doc, {locationInfo: true });
34- ```
24+ var vfile = require (' to-vfile' );
25+ var parse5 = require (' parse5' );
26+ var inspect = require (' unist-util-inspect' );
27+ var fromParse5 = require (' hast-util-from-parse5' );
3528
36- Transform:
29+ var doc = vfile .readSync (' example.html' )
30+ var ast = parse5 .parse (String (doc), {locationInfo: true });
31+ var hast = fromParse5 (ast, doc);
3732
38- ``` javascript
39- var hast = fromParse5 (ast, vfile (doc));
33+ console .log (inspect (hast));
4034```
4135
42- Yields :
36+ Now, running ` node example ` yields :
4337
44- ``` txt
45- root[2] (1:1-1:70 , 0-69 ) [data={"quirksMode":false}]
38+ ``` text
39+ root[2] (1:1-2:1 , 0-70 ) [data={"quirksMode":false}]
4640├─ doctype (1:1-1:16, 0-15) [name="html"]
4741└─ element[2] [tagName="html"]
4842 ├─ element[1] [tagName="head"]
4943 │ └─ element[1] (1:16-1:37, 15-36) [tagName="title"]
5044 │ └─ text: "Hello!" (1:23-1:29, 22-28)
5145 └─ element[1] [tagName="body"]
52- └─ element[2 ] (1:37-1:70 , 36-69 ) [tagName="h1"][properties={"id":"world"}]
46+ └─ element[3 ] (1:37-2:1 , 36-70 ) [tagName="h1"][properties={"id":"world"}]
5347 ├─ text: "World!" (1:52-1:58, 51-57)
54- └─ comment: "after" (1:58-1:70, 57-69)
48+ ├─ comment: "after" (1:58-1:70, 57-69)
49+ └─ text: "\n" (1:70-2:1, 69-70)
5550```
5651
5752## API
0 commit comments