17
17
* [ Install] ( #install )
18
18
* [ Use] ( #use )
19
19
* [ API] ( #api )
20
- * [ ` toXast(node[, space|options]) ` ] ( #toxastnode-spaceoptions )
20
+ * [ ` toXast(tree[, space|options]) ` ] ( #toxasttree-spaceoptions )
21
+ * [ ` Options ` ] ( #options )
22
+ * [ ` Space ` ] ( #space-1 )
21
23
* [ Types] ( #types )
22
24
* [ Compatibility] ( #compatibility )
23
25
* [ Security] ( #security )
@@ -45,7 +47,7 @@ hast into estree (JavaScript) as JSX, which has some similarities to XML.
45
47
## Install
46
48
47
49
This package is [ ESM only] [ esm ] .
48
- In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
50
+ In Node.js (version 14.14+ and or 16.0+), install with [ npm] [ ] :
49
51
50
52
``` sh
51
53
npm install hast-util-to-xast
@@ -103,38 +105,62 @@ console.log(toXml(xast))
103
105
104
106
## API
105
107
106
- This package exports the identifier ` toXast ` .
108
+ This package exports the identifier [ ` toXast ` ] [ toxast ] .
107
109
There is no default export.
108
110
109
- ### ` toXast(node [, space|options]) `
111
+ ### ` toXast(tree [, space|options]) `
110
112
111
- [ hast] [ ] utility to transform to [ xast] [ ] .
113
+ Turn a [ hast] [ ] tree into a [ xast] [ ] tree .
112
114
113
- ##### ` options `
115
+ ###### Parameters
114
116
115
- Configuration (optional).
117
+ * ` tree ` ([ ` HastNode ` ] [ hast-node ] )
118
+ — hast tree to transform
119
+ * ` space ` ([ ` Space ` ] [ space ] , optional)
120
+ — same as options of ` {space: space} `
121
+ * ` options ` ([ ` Options ` ] [ options ] , optional)
122
+ — configuration
116
123
117
- ###### ` options.space `
124
+ ###### Returns
118
125
119
- Whether the given ` node ` is in the HTML or SVG space (enum, ` 'svg' ` or ` 'html' ` ,
120
- default: ` 'html' ` ).
126
+ xast tree ([ ` XastNode ` ] [ xast-node ] ).
121
127
122
- If an ` svg ` element is found in the HTML space, ` toXast ` automatically switches
123
- to the SVG space when entering the element, and switches back when exiting.
128
+ ### ` Options `
129
+
130
+ Configuration (TypeScript type).
131
+
132
+ ##### Fields
133
+
134
+ ###### ` space `
135
+
136
+ Which space the document is in.
137
+
138
+ When an ` <svg> ` element is found in the HTML space, this package already
139
+ automatically switches to and from the SVG space when entering and exiting it.
124
140
125
141
You can also switch explicitly with ` xmlns ` properties in hast, but note that
126
142
only HTML and SVG are supported.
127
143
144
+ ### ` Space `
145
+
146
+ Namespace (TypeScript type).
147
+
148
+ ###### Type
149
+
150
+ ``` ts
151
+ type Space = ' html' | ' svg'
152
+ ` ` `
153
+
128
154
## Types
129
155
130
156
This package is fully typed with [TypeScript][].
131
- It exports the additional types ` Options ` and ` Space ` .
157
+ It exports the additional types [ ` Options ` ][options] and [ ` Space ` ][space] .
132
158
133
159
## Compatibility
134
160
135
161
Projects maintained by the unified collective are compatible with all maintained
136
162
versions of Node.js.
137
- As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18 .0+.
163
+ As of now, that is Node.js 14.14+ and 16 .0+.
138
164
Our projects sometimes work with older versions, but this is not guaranteed.
139
165
140
166
## Security
@@ -145,9 +171,9 @@ using this utility.
145
171
146
172
## Related
147
173
148
- * [ ` hastscript ` ] [ h ]
174
+ * [ ` hastscript ` ](https://github.com/syntax-tree/hastscript)
149
175
— create **[hast][]** (HTML or SVG) trees
150
- * [ ` xastscript ` ] [ x ]
176
+ * [ ` xastscript ` ](https://github.com/syntax-tree/xastscript)
151
177
— create **[xast][]** (XML) trees
152
178
* [ ` xast -util -to -xml ` ](https://github.com/syntax-tree/xast-util-to-xml)
153
179
— serialize as XML
@@ -216,12 +242,18 @@ abide by its terms.
216
242
217
243
[hast]: https://github.com/syntax-tree/hast
218
244
219
- [ xast ] : https://github.com/syntax-tree/xast
245
+ [hast-node ]: https://github.com/syntax-tree/hast#nodes
220
246
221
247
[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize
222
248
223
- [ h ] : https://github.com/syntax-tree/hastscript
249
+ [hast-util-to-estree]: https://github.com/syntax-tree/hast-util-to-estree
250
+
251
+ [xast]: https://github.com/syntax-tree/xast
224
252
225
- [ x ] : https://github.com/syntax-tree/xastscript
253
+ [xast-node ]: https://github.com/syntax-tree/xast#nodes
226
254
227
- [ hast-util-to-estree ] : https://github.com/syntax-tree/hast-util-to-estree
255
+ [toxast]: #toxasttree-spaceoptions
256
+
257
+ [options]: #options
258
+
259
+ [space]: #space-1
0 commit comments