1
- # hast-util-from-parse5 [ ![ Build ] [ build-badge ]] [ build ] [ ![ Coverage ] [ coverage-badge ]] [ coverage ] [ ![ Downloads ] [ downloads-badge ]] [ downloads ] [ ![ Chat ] [ chat-badge ]] [ chat ]
1
+ # hast-util-from-parse5
2
2
3
- Transform [ Parse5’s AST] [ ast ] to [ HAST] [ ] .
3
+ [ ![ Build] [ build-badge ]] [ build ]
4
+ [ ![ Coverage] [ coverage-badge ]] [ coverage ]
5
+ [ ![ Downloads] [ downloads-badge ]] [ downloads ]
6
+ [ ![ Size] [ size-badge ]] [ size ]
7
+ [ ![ Sponsors] [ sponsors-badge ]] [ collective ]
8
+ [ ![ Backers] [ backers-badge ]] [ collective ]
9
+ [ ![ Chat] [ chat-badge ]] [ chat ]
4
10
5
- ## Installation
11
+ [ ** hast** ] [ hast ] utility to transform [ Parse5’s AST] [ ast ] to a hast
12
+ [ * tree* ] [ tree ] .
13
+
14
+ ## Install
6
15
7
16
[ npm] [ ] :
8
17
9
- ``` bash
18
+ ``` sh
10
19
npm install hast-util-from-parse5
11
20
```
12
21
@@ -20,7 +29,7 @@ Say we have the following file, `example.html`:
20
29
21
30
And our script, ` example.js ` , looks as follows:
22
31
23
- ``` javascript
32
+ ``` js
24
33
var vfile = require (' to-vfile' )
25
34
var parse5 = require (' parse5' )
26
35
var inspect = require (' unist-util-inspect' )
@@ -53,31 +62,33 @@ root[2] (1:1-2:1, 0-70) [data={"quirksMode":false}]
53
62
54
63
### ` fromParse5(ast[, options]) `
55
64
56
- Transform an ` ASTNode ` to a [ HAST Node ] [ node ] .
65
+ Transform [ Parse5’s AST ] [ ast ] to a [ ** hast ** ] [ hast ] [ * tree * ] [ tree ] .
57
66
58
67
##### ` options `
59
68
60
- If ` options ` is a [ VFile] [ ] , it’s treated as ` {file: options} ` .
69
+ If ` options ` is a [ ` VFile ` ] [ vfile ] , it’s treated as ` {file: options} ` .
61
70
62
71
###### ` options.space `
63
72
64
- Whether the root of the given tree is in the ` 'html' ` or ` 'svg' ` space (enum,
65
- ` 'svg' ` or ` 'html' ` , default: ` 'html' ` ).
73
+ Whether the [ * root* ] [ root ] of the [ * tree* ] [ tree ] is in the ` 'html' ` or ` 'svg' `
74
+ space (enum, ` 'svg' ` or ` 'html' ` , default: ` 'html' ` ).
66
75
67
76
If an element in with the SVG namespace is found in ` ast ` , ` fromParse5 `
68
- automatically switches to the SVG space when entering the element, and
69
- switches back when leaving.
77
+ automatically switches to the SVG space when entering the element, and switches
78
+ back when leaving.
70
79
71
80
###### ` options.file `
72
81
73
- [ Virtual file] [ vfile ] , used to add positional information to HAST nodes.
74
- If given, the file should have the original HTML source as its contents.
82
+ [ ` VFile ` ] [ vfile ] , used to add [ positional information] [ positional-information ]
83
+ to [ * nodes* ] [ node ] .
84
+ If given, the [ * file* ] [ file ] should have the original HTML source as its
85
+ contents.
75
86
76
87
###### ` options.verbose `
77
88
78
- Whether to add positional information about starting tags, closing tags,
79
- and attributes to elements (` boolean ` , default: ` false ` ). Note: not used
80
- without ` file ` .
89
+ Whether to add extra positional information about starting tags, closing tags,
90
+ and attributes to elements (` boolean ` , default: ` false ` ).
91
+ Note: not used without ` file ` .
81
92
82
93
For the following HTML:
83
94
@@ -91,11 +102,7 @@ The verbose info would looks as follows:
91
102
{
92
103
type: ' element' ,
93
104
tagName: ' img' ,
94
- properties: {
95
- src: ' http://example.com/fav.ico' ,
96
- alt: ' foo' ,
97
- title: ' bar'
98
- },
105
+ properties: {src: ' http://example.com/fav.ico' , alt: ' foo' , title: ' bar' },
99
106
children: [],
100
107
data: {
101
108
position: {
@@ -129,11 +136,13 @@ The verbose info would looks as follows:
129
136
130
137
## Contribute
131
138
132
- See [ ` contributing.md ` in ` syntax-tree/hast ` ] [ contributing ] for ways to get
139
+ See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
133
140
started.
141
+ See [ ` support.md ` ] [ support ] for ways to get help.
134
142
135
- This organisation has a [ Code of Conduct] [ coc ] . By interacting with this
136
- repository, organisation, or community you agree to abide by its terms.
143
+ This project has a [ Code of Conduct] [ coc ] .
144
+ By interacting with this repository, organisation, or community you agree to
145
+ abide by its terms.
137
146
138
147
## License
139
148
@@ -153,24 +162,44 @@ repository, organisation, or community you agree to abide by its terms.
153
162
154
163
[ downloads ] : https://www.npmjs.com/package/hast-util-from-parse5
155
164
165
+ [ size-badge ] : https://img.shields.io/bundlephobia/minzip/hast-util-from-parse5.svg
166
+
167
+ [ size ] : https://bundlephobia.com/result?p=hast-util-from-parse5
168
+
169
+ [ sponsors-badge ] : https://opencollective.com/unified/sponsors/badge.svg
170
+
171
+ [ backers-badge ] : https://opencollective.com/unified/backers/badge.svg
172
+
173
+ [ collective ] : https://opencollective.com/unified
174
+
156
175
[ chat-badge ] : https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
157
176
158
- [ chat ] : https://spectrum.chat/unified/rehype
177
+ [ chat ] : https://spectrum.chat/unified/syntax-tree
159
178
160
179
[ npm ] : https://docs.npmjs.com/cli/install
161
180
162
181
[ license ] : license
163
182
164
183
[ author ] : https://wooorm.com
165
184
166
- [ hast ] : https://github.com/syntax-tree/hast
185
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/master/contributing.md
167
186
168
- [ ast ] : https://github.com/inikulin/parse5/blob/master/packages/parse5/docs/tree-adapter/default/interface-list.md
187
+ [ support ] : https://github.com/syntax-tree/.github/blob/master/support.md
188
+
189
+ [ coc ] : https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
169
190
170
- [ node ] : https://github.com/syntax- tree/hast#ast
191
+ [ ast ] : https://github.com/inikulin/parse5/blob/master/packages/parse5/docs/ tree-adapter/default/interface-list.md
171
192
172
193
[ vfile ] : https://github.com/vfile/vfile
173
194
174
- [ contributing ] : https://github.com/syntax-tree/hast/blob/master/contributing.md
195
+ [ tree ] : https://github.com/syntax-tree/unist#tree
196
+
197
+ [ root ] : https://github.com/syntax-tree/unist#root
198
+
199
+ [ positional-information ] : https://github.com/syntax-tree/unist#positional-information
200
+
201
+ [ file ] : https://github.com/syntax-tree/unist#file
202
+
203
+ [ hast ] : https://github.com/syntax-tree/hast
175
204
176
- [ coc ] : https://github.com/syntax-tree/hast/blob/master/code-of-conduct.md
205
+ [ node ] : https://github.com/syntax-tree/hast#nodes
0 commit comments