|
18 | 18 | * [Use](#use)
|
19 | 19 | * [API](#api)
|
20 | 20 | * [`toXml(tree[, options])`](#toxmltree-options)
|
| 21 | + * [`Options`](#options) |
| 22 | + * [`Quote`](#quote-1) |
21 | 23 | * [Types](#types)
|
22 | 24 | * [Compatibility](#compatibility)
|
23 | 25 | * [Security](#security)
|
@@ -50,7 +52,7 @@ utility but for HTML: it turns [hast][] into HTML.
|
50 | 52 | ## Install
|
51 | 53 |
|
52 | 54 | This package is [ESM only][esm].
|
53 |
| -In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]: |
| 55 | +In Node.js (version 14.14+ and 16.0+), install with [npm][]: |
54 | 56 |
|
55 | 57 | ```sh
|
56 | 58 | npm install xast-util-to-xml
|
@@ -113,48 +115,76 @@ Yields:
|
113 | 115 |
|
114 | 116 | ## API
|
115 | 117 |
|
116 |
| -This package exports the identifier `toXml`. |
| 118 | +This package exports the identifier [`toXml`][toxml]. |
117 | 119 | There is no default export.
|
118 | 120 |
|
119 | 121 | ### `toXml(tree[, options])`
|
120 | 122 |
|
121 |
| -Serialize the given [xast][] node (or list of nodes). |
| 123 | +Serialize a xast tree to XML. |
122 | 124 |
|
123 |
| -##### `options` |
| 125 | +###### Parameters |
124 | 126 |
|
125 |
| -Configuration (optional). |
| 127 | +* `tree` ([`Node`][node] or `Array<Node>`) |
| 128 | + — xast node(s) to serialize |
| 129 | +* `options` ([`Options`][options], optional) |
| 130 | + — configuration |
126 | 131 |
|
127 |
| -###### `options.quote` |
| 132 | +###### Returns |
128 | 133 |
|
129 |
| -Preferred quote to use (`'"'` or `'\''`, default: `'"'`). |
| 134 | +Serialized XML (`string`). |
130 | 135 |
|
131 |
| -###### `options.quoteSmart` |
| 136 | +### `Options` |
132 | 137 |
|
133 |
| -Use the other quote if that results in less bytes (`boolean`, default: `false`). |
| 138 | +Configuration (TypeScript type). |
134 | 139 |
|
135 |
| -###### `options.closeEmptyElements` |
| 140 | +##### Fields |
| 141 | + |
| 142 | +###### `allowDangerousXml` |
| 143 | + |
| 144 | +Allow `raw` nodes and insert them as raw XML (`boolean`, default: `false`). |
| 145 | + |
| 146 | +When `false`, `Raw` nodes are encoded. |
| 147 | + |
| 148 | +> ⚠️ **Danger**: only set this if you completely trust the content. |
| 149 | +
|
| 150 | +###### `closeEmptyElements` |
| 151 | + |
| 152 | +Close elements without any content with slash (`/`) on the opening tag instead |
| 153 | +of an end tag: `<circle />` instead of `<circle></circle>` (`boolean`, default: |
| 154 | +`false`). |
136 | 155 |
|
137 |
| -Close elements without any content with slash (`/`) on the opening tag |
138 |
| -instead of an end tag: `<circle />` instead of `<circle></circle>` (`boolean`, |
139 |
| -default: `false`). |
140 | 156 | See `tightClose` to control whether a space is used before the slash.
|
141 | 157 |
|
142 |
| -###### `options.tightClose` |
| 158 | +###### `quote` |
| 159 | + |
| 160 | +Preferred quote to use ([`Quote`][quote], default: `'"'`). |
| 161 | + |
| 162 | +###### `quoteSmart` |
| 163 | + |
| 164 | +Use the other quote if that results in less bytes (`boolean`, default: |
| 165 | +`false`). |
| 166 | + |
| 167 | +###### `tightClose` |
143 | 168 |
|
144 | 169 | Do not use an extra space when closing self-closing elements: `<circle/>`
|
145 | 170 | instead of `<circle />` (`boolean`, default: `false`).
|
146 | 171 |
|
147 |
| -###### `options.allowDangerousXml` |
| 172 | +> 👉 **Note**: only used if `closeEmptyElements: true`. |
| 173 | +
|
| 174 | +### `Quote` |
148 | 175 |
|
149 |
| -Allow `raw` nodes and insert them as raw XML. |
150 |
| -When falsey, encodes `raw` nodes (`boolean`, default: `false`). |
| 176 | +XML quotes for attribute values (TypeScript type). |
151 | 177 |
|
152 |
| -> ☢️ **Danger**: only set this if you completely trust the content. |
| 178 | +###### Type |
| 179 | + |
| 180 | +```ts |
| 181 | +type Quote = '"' | "'" |
| 182 | +``` |
153 | 183 |
|
154 | 184 | ## Types
|
155 | 185 |
|
156 | 186 | This package is fully typed with [TypeScript][].
|
157 |
| -It exports the additional type `Options`. |
| 187 | +It exports the additional types [`Options`][options] and [`Quote`][quote]. |
158 | 188 |
|
159 | 189 | ## Compatibility
|
160 | 190 |
|
@@ -240,8 +270,16 @@ abide by its terms.
|
240 | 270 |
|
241 | 271 | [xast]: https://github.com/syntax-tree/xast
|
242 | 272 |
|
| 273 | +[node]: https://github.com/syntax-tree/xast#nodes |
| 274 | +
|
243 | 275 | [hast]: https://github.com/syntax-tree/hast
|
244 | 276 |
|
245 | 277 | [xast-util-from-xml]: https://github.com/syntax-tree/xast-util-from-xml
|
246 | 278 |
|
247 | 279 | [hast-util-to-html]: https://github.com/syntax-tree/hast-util-to-html
|
| 280 | +
|
| 281 | +[toxml]: #toxmltree-options |
| 282 | +
|
| 283 | +[options]: #options |
| 284 | +
|
| 285 | +[quote]: #quote-1 |
0 commit comments