Skip to content

Commit 133b1c0

Browse files
committed
Add improved docs
1 parent 945cf49 commit 133b1c0

File tree

3 files changed

+56
-21
lines changed

3 files changed

+56
-21
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @typedef {import('./lib/index.js').Space} Space
32
* @typedef {import('./lib/index.js').Options} Options
3+
* @typedef {import('./lib/index.js').Space} Space
44
*/
55

66
export {toXast} from './lib/index.js'

lib/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
* automatically switches to and from the SVG space when entering and exiting
3434
* it.
3535
*
36+
* You can also switch explicitly with `xmlns` properties in hast, but note
37+
* that only HTML and SVG are supported.
38+
*
3639
* @typedef State
3740
* Info passed around about the current state.
3841
* @property {Schema} schema

readme.md

+52-20
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`toXast(node[, space|options])`](#toxastnode-spaceoptions)
20+
* [`toXast(tree[, space|options])`](#toxasttree-spaceoptions)
21+
* [`Options`](#options)
22+
* [`Space`](#space-1)
2123
* [Types](#types)
2224
* [Compatibility](#compatibility)
2325
* [Security](#security)
@@ -45,7 +47,7 @@ hast into estree (JavaScript) as JSX, which has some similarities to XML.
4547
## Install
4648

4749
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][]:
4951

5052
```sh
5153
npm install hast-util-to-xast
@@ -103,38 +105,62 @@ console.log(toXml(xast))
103105

104106
## API
105107

106-
This package exports the identifier `toXast`.
108+
This package exports the identifier [`toXast`][toxast].
107109
There is no default export.
108110

109-
### `toXast(node[, space|options])`
111+
### `toXast(tree[, space|options])`
110112

111-
[hast][] utility to transform to [xast][].
113+
Turn a [hast][] tree into a [xast][] tree.
112114

113-
##### `options`
115+
###### Parameters
114116

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
116123

117-
###### `options.space`
124+
###### Returns
118125

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]).
121127

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.
124140

125141
You can also switch explicitly with `xmlns` properties in hast, but note that
126142
only HTML and SVG are supported.
127143

144+
### `Space`
145+
146+
Namespace (TypeScript type).
147+
148+
###### Type
149+
150+
```ts
151+
type Space = 'html' | 'svg'
152+
```
153+
128154
## Types
129155
130156
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].
132158
133159
## Compatibility
134160
135161
Projects maintained by the unified collective are compatible with all maintained
136162
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+.
138164
Our projects sometimes work with older versions, but this is not guaranteed.
139165
140166
## Security
@@ -145,9 +171,9 @@ using this utility.
145171
146172
## Related
147173
148-
* [`hastscript`][h]
174+
* [`hastscript`](https://github.com/syntax-tree/hastscript)
149175
— create **[hast][]** (HTML or SVG) trees
150-
* [`xastscript`][x]
176+
* [`xastscript`](https://github.com/syntax-tree/xastscript)
151177
— create **[xast][]** (XML) trees
152178
* [`xast-util-to-xml`](https://github.com/syntax-tree/xast-util-to-xml)
153179
— serialize as XML
@@ -216,12 +242,18 @@ abide by its terms.
216242
217243
[hast]: https://github.com/syntax-tree/hast
218244
219-
[xast]: https://github.com/syntax-tree/xast
245+
[hast-node]: https://github.com/syntax-tree/hast#nodes
220246
221247
[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize
222248
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
224252
225-
[x]: https://github.com/syntax-tree/xastscript
253+
[xast-node]: https://github.com/syntax-tree/xast#nodes
226254
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

Comments
 (0)