@@ -35,32 +35,40 @@ var parse5 = require('parse5')
35
35
var inspect = require (' unist-util-inspect' )
36
36
var fromParse5 = require (' hast-util-from-parse5' )
37
37
38
- var doc = vfile .readSync (' example.html' )
39
- var ast = parse5 .parse (String (doc ), {sourceCodeLocationInfo: true })
40
- var hast = fromParse5 (ast, doc )
38
+ var file = vfile .readSync (' example.html' )
39
+ var p5ast = parse5 .parse (String (file ), {sourceCodeLocationInfo: true })
40
+ var hast = fromParse5 (p5ast, file )
41
41
42
42
console .log (inspect (hast))
43
43
```
44
44
45
45
Now, running ` node example ` yields:
46
46
47
47
``` text
48
- root[2] (1:1-2:1, 0-70) [data={"quirksMode":false}]
49
- ├─ doctype (1:1-1:16, 0-15) [name="html"]
50
- └─ element[2] [tagName="html"]
51
- ├─ element[1] [tagName="head"]
52
- │ └─ element[1] (1:16-1:37, 15-36) [tagName="title"]
53
- │ └─ text: "Hello!" (1:23-1:29, 22-28)
54
- └─ element[1] [tagName="body"]
55
- └─ element[3] (1:37-2:1, 36-70) [tagName="h1"][properties={"id":"world"}]
56
- ├─ text: "World!" (1:52-1:58, 51-57)
57
- ├─ comment: "after" (1:58-1:70, 57-69)
58
- └─ text: "\n" (1:70-2:1, 69-70)
48
+ root[2] (1:1-2:1, 0-70)
49
+ │ data: {"quirksMode":false}
50
+ ├─0 doctype<html> (1:1-1:16, 0-15)
51
+ │ public: null
52
+ │ system: null
53
+ └─1 element<html>[2]
54
+ │ properties: {}
55
+ ├─0 element<head>[1]
56
+ │ │ properties: {}
57
+ │ └─0 element<title>[1] (1:16-1:37, 15-36)
58
+ │ │ properties: {}
59
+ │ └─0 text "Hello!" (1:23-1:29, 22-28)
60
+ └─1 element<body>[1]
61
+ │ properties: {}
62
+ └─0 element<h1>[3] (1:37-2:1, 36-70)
63
+ │ properties: {"id":"world"}
64
+ ├─0 text "World!" (1:52-1:58, 51-57)
65
+ ├─1 comment "after" (1:58-1:70, 57-69)
66
+ └─2 text "\n" (1:70-2:1, 69-70)
59
67
```
60
68
61
69
## API
62
70
63
- ### ` fromParse5(ast[, options]) `
71
+ ### ` fromParse5(ast[, file| options]) `
64
72
65
73
Transform [ Parse5’s AST] [ ast ] to a [ ** hast** ] [ hast ] [ * tree* ] [ tree ] .
66
74
0 commit comments