Skip to content

Commit 9d43892

Browse files
committed
Add improved docs
1 parent 8d71bdd commit 9d43892

File tree

2 files changed

+51
-18
lines changed

2 files changed

+51
-18
lines changed

Diff for: lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ const own = {}.hasOwnProperty
4545
const one = zwitch('type', {handlers: {root, element, text, comment, doctype}})
4646

4747
/**
48-
* Transform a tree from hast to Parse5’s AST.
48+
* Transform a hast tree to Parse5’s AST.
4949
*
5050
* @param {Node} tree
5151
* Tree to transform.
5252
* @param {Options | Space | null | undefined} [options]
53-
* Current space.
53+
* Configuration.
5454
* @returns {P5Node}
5555
* `parse5` node.
5656
*/

Diff for: readme.md

+49-16
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
[hast][] utility to generate [`parse5`][parse5]s [AST][].
11+
[hast][] utility to generate [`parse5`][parse5]s [AST][parse5-node].
1212

1313
## Contents
1414

@@ -17,7 +17,9 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`toParse5(tree[, space])`](#toparse5tree-space)
20+
* [`toParse5(tree[, space|options])`](#toparse5tree-spaceoptions)
21+
* [`Options`](#options)
22+
* [`Space`](#space)
2123
* [Types](#types)
2224
* [Compatibility](#compatibility)
2325
* [Security](#security)
@@ -41,7 +43,7 @@ likely what you want.
4143
## Install
4244

4345
This package is [ESM only][esm].
44-
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
46+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
4547

4648
```sh
4749
npm install hast-util-to-parse5
@@ -88,32 +90,55 @@ Yields:
8890

8991
## API
9092

91-
This package exports the identifier `toParse5`.
93+
This package exports the identifier [`toParse5`][toparse5].
9294
There is no default export.
9395

94-
### `toParse5(tree[, space])`
96+
### `toParse5(tree[, space|options])`
9597

96-
[hast][] utility to transform to [`parse5`][parse5]s [ast][].
98+
Transform a hast tree to Parse5’s AST.
9799

98-
###### `space`
100+
###### Parameters
99101

100-
Whether the root of the given tree is in the HTML or SVG space (enum, `'svg'` or
101-
`'html'`, default: `'html'`).
102+
* `tree` ([`HastNode`][hast-node])
103+
— tree to transform
104+
* `space` ([`Space`][space], optional)
105+
— same as `{space: space}`
106+
* `options` ([`Options`][options], optional)
107+
— configuration
102108

103-
If an `svg` element is found in the HTML space, `toParse5` automatically
104-
switches to the SVG space when entering the element, and switches back when
105-
exiting.
109+
###### Returns
110+
111+
`parse5` node ([`Parse5Node`][parse5-node]).
112+
113+
### `Options`
114+
115+
Configuration (TypeScript type).
116+
117+
###### Fields
118+
119+
* `space` ([`Space`][space], optional)
120+
— which space the document is in
121+
122+
### `Space`
123+
124+
Namespace (TypeScript type).
125+
126+
###### Type
127+
128+
```ts
129+
type Space = 'html' | 'svg'
130+
```
106131
107132
## Types
108133
109134
This package is fully typed with [TypeScript][].
110-
It exports the additional type `Space`.
135+
It exports the additional types [`Options`][options] and [`Space`][space].
111136
112137
## Compatibility
113138
114139
Projects maintained by the unified collective are compatible with all maintained
115140
versions of Node.js.
116-
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
141+
As of now, that is Node.js 14.14+ and 16.0+.
117142
Our projects sometimes work with older versions, but this is not guaranteed.
118143
119144
## Security
@@ -198,12 +223,20 @@ abide by its terms.
198223
199224
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
200225
226+
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
227+
201228
[hast]: https://github.com/syntax-tree/hast
202229
203-
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
230+
[hast-node]: https://github.com/syntax-tree/hast#nodes
204231
205232
[parse5]: https://github.com/inikulin/parse5
206233
207-
[ast]: https://github.com/inikulin/parse5/wiki/Documentation
234+
[parse5-node]: https://github.com/inikulin/parse5/blob/master/packages/parse5/lib/tree-adapters/default.ts
208235
209236
[hast-util-from-parse5]: https://github.com/syntax-tree/hast-util-from-parse5
237+
238+
[toparse5]: #toparse5tree-spaceoptions
239+
240+
[options]: #options
241+
242+
[space]: #space

0 commit comments

Comments
 (0)