8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- [ hast] [ ] utility to transform from [ ` parse5 ` ] [ parse5 ] s [ AST] [ ] .
11
+ [ hast] [ ] utility to transform from [ ` parse5 ` ] [ parse5 ] s AST.
12
12
13
13
## Contents
14
14
17
17
* [ Install] ( #install )
18
18
* [ Use] ( #use )
19
19
* [ API] ( #api )
20
- * [ ` fromParse5(ast[, file|options]) ` ] ( #fromparse5ast-fileoptions )
20
+ * [ ` fromParse5(tree[, file|options]) ` ] ( #fromparse5tree-fileoptions )
21
+ * [ ` Options ` ] ( #options )
22
+ * [ ` Space ` ] ( #space-1 )
21
23
* [ Types] ( #types )
22
24
* [ Compatibility] ( #compatibility )
23
25
* [ Security] ( #security )
@@ -44,7 +46,7 @@ The utility [`hast-util-from-html`][hast-util-from-html] wraps this utility and
44
46
## Install
45
47
46
48
This package is [ ESM only] [ esm ] .
47
- In Node.js (version 12.20+, 14.14+, 16.0+, 18 .0+), install with [ npm] [ ] :
49
+ In Node.js (version 14.14+ and 16 .0+), install with [ npm] [ ] :
48
50
49
51
``` sh
50
52
npm install hast-util-from-parse5
@@ -113,38 +115,52 @@ root[2] (1:1-2:1, 0-70)
113
115
114
116
## API
115
117
116
- This package exports the identifier ` fromParse5 ` .
118
+ This package exports the identifier [ ` fromParse5 ` ] [ fromparse5 ] .
117
119
There is no default export.
118
120
119
- ### ` fromParse5(ast [, file|options]) `
121
+ ### ` fromParse5(tree [, file|options]) `
120
122
121
- Transform from [ ` parse5 ` ] [ parse5 ] s [ AST] [ ] .
123
+ Transform a ` parse5 ` AST to hast .
122
124
123
- ##### ` options `
125
+ ###### Parameters
124
126
125
- If ` options ` is a [ ` VFile ` ] [ vfile ] , it’s treated as ` {file: options} ` .
127
+ * ` tree ` ([ ` Parse5Node ` ] [ parse5-node ] )
128
+ — ` parse5 ` tree to transform
129
+ * ` file ` ([ ` VFile ` ] [ vfile ] , optional)
130
+ — corresponding file (treated as ` {file: file} ` )
131
+ * ` options ` ([ ` Options ` ] [ options ] , optional)
132
+ — configuration
126
133
127
- ###### ` options.space `
134
+ ###### Returns
128
135
129
- Whether the [ * root* ] [ root ] of the [ * tree* ] [ tree ] is in the HTML or SVG space
130
- (enum, ` 'svg' ` or ` 'html' ` , default: ` 'html' ` ).
136
+ hast tree ([ ` HastNode ` ] [ hast-node ] ).
131
137
132
- If an element in with the SVG namespace is found in ` ast ` , ` fromParse5 `
133
- automatically switches to the SVG space when entering the element, and switches
134
- back when leaving.
138
+ ### ` Options `
135
139
136
- ###### ` options.file `
140
+ Configuration (TypeScript type).
137
141
138
- [ ` VFile ` ] [ vfile ] , used to add [ positional information] [ positional-information ]
139
- to [ * nodes* ] [ node ] .
140
- If given, the [ * file* ] [ file ] should have the original HTML source as its
141
- contents.
142
+ ##### Fields
142
143
143
- ###### ` options.verbose `
144
+ ###### ` space `
144
145
145
- Whether to add extra positional information about starting tags, closing tags,
146
+ Which space the document is in ([ ` Space ` ] [ space ] , default: ` 'html' ` ).
147
+
148
+ When an ` <svg> ` element is found in the HTML space, this package already
149
+ automatically switches to and from the SVG space when entering and exiting
150
+ it.
151
+
152
+ ###### ` file `
153
+
154
+ File used to add positional info to nodes ([ ` VFile ` ] [ vfile ] , optional).
155
+
156
+ If given, the file should represent the original HTML source.
157
+
158
+ ###### ` verbose `
159
+
160
+ Whether to add extra positional info about starting tags, closing tags,
146
161
and attributes to elements (` boolean ` , default: ` false ` ).
147
- Note: not used without ` file ` .
162
+
163
+ > 👉 ** Note** : only used when ` file ` is given.
148
164
149
165
For the following HTML:
150
166
@@ -190,10 +206,20 @@ The verbose info would looks as follows:
190
206
}
191
207
```
192
208
209
+ ### ` Space `
210
+
211
+ Namespace (TypeScript type).
212
+
213
+ ###### Type
214
+
215
+ ``` ts
216
+ type Space = ' html' | ' svg'
217
+ ` ` `
218
+
193
219
## Types
194
220
195
221
This package is fully typed with [TypeScript][].
196
- It exports the additional type ` Options ` .
222
+ It exports the additional types [ ` Options ` ][options] and [ ` Space ` ][space] .
197
223
198
224
## Compatibility
199
225
@@ -288,22 +314,20 @@ abide by its terms.
288
314
289
315
[parse5]: https://github.com/inikulin/parse5
290
316
291
- [ ast ] : https://github.com/inikulin/parse5/blob/HEAD /packages/parse5/docs /tree-adapter /default/interface-list.md
317
+ [parse5-node ]: https://github.com/inikulin/parse5/blob/master /packages/parse5/lib /tree-adapters /default.ts
292
318
293
319
[vfile]: https://github.com/vfile/vfile
294
320
295
- [ tree ] : https://github.com/syntax-tree/unist#tree
296
-
297
- [ root ] : https://github.com/syntax-tree/unist#root
298
-
299
- [ positional-information ] : https://github.com/syntax-tree/unist#positional-information
300
-
301
321
[hast-util-to-parse5]: https://github.com/syntax-tree/hast-util-to-parse5
302
322
303
- [ file ] : https://github.com/syntax-tree/unist#file
304
-
305
323
[hast]: https://github.com/syntax-tree/hast
306
324
307
325
[hast-util-from-html]: https://github.com/syntax-tree/hast-util-from-html
308
326
309
- [ node ] : https://github.com/syntax-tree/hast#nodes
327
+ [hast-node]: https://github.com/syntax-tree/hast#nodes
328
+
329
+ [fromparse5]: #fromparse5tree-fileoptions
330
+
331
+ [options]: #options
332
+
333
+ [space]: #space-1
0 commit comments