Skip to content

Commit 804fc7c

Browse files
committed
Add improved docs
1 parent ab054c7 commit 804fc7c

File tree

1 file changed

+78
-19
lines changed

1 file changed

+78
-19
lines changed

readme.md

Lines changed: 78 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,59 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
[**hast**][hast] utility to transform to [Parse5’s AST][ast].
11+
[hast][] utility to generate [`parse5`][parse5]s [AST][].
1212

13-
> **Q**: Why not use a Parse5 adapter?
14-
> **A**: Because it’s more code weight to use adapters, and much more fragile.
13+
## Contents
1514

16-
## Install
15+
* [What is this?](#what-is-this)
16+
* [When should I use this?](#when-should-i-use-this)
17+
* [Install](#install)
18+
* [Use](#use)
19+
* [API](#api)
20+
* [`toParse5(tree[, space])`](#toparse5tree-space)
21+
* [Types](#types)
22+
* [Compatibility](#compatibility)
23+
* [Security](#security)
24+
* [Related](#related)
25+
* [Contribute](#contribute)
26+
* [License](#license)
27+
28+
## What is this?
1729

18-
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
19-
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
30+
This package is a utility that can turn a hast syntax tree into `parse5`s AST.
31+
Why not use a Parse5 adapter, you might ask?
32+
Well, because it’s more code weight to use adapters, and more fragile.
2033

21-
[npm][]:
34+
## When should I use this?
35+
36+
This package is useful when working with `parse5`, and for some reason want to
37+
generate its AST again.
38+
The inverse utility, [`hast-util-from-parse5`][hast-util-from-parse5], is more
39+
likely what you want.
40+
41+
## Install
42+
43+
This package is [ESM only][esm].
44+
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
2245

2346
```sh
2447
npm install hast-util-to-parse5
2548
```
2649

50+
In Deno with [`esm.sh`][esmsh]:
51+
52+
```js
53+
import {toParse5} from 'https://esm.sh/hast-util-to-parse5@7'
54+
```
55+
56+
In browsers with [`esm.sh`][esmsh]:
57+
58+
```html
59+
<script type="module">
60+
import {toParse5} from 'https://esm.sh/hast-util-to-parse5@7?bundle'
61+
</script>
62+
```
63+
2764
## Use
2865

2966
```js
@@ -51,22 +88,34 @@ Yields:
5188

5289
## API
5390

54-
This package exports the following identifiers: `toParse5`.
91+
This package exports the identifier `toParse5`.
5592
There is no default export.
5693

5794
### `toParse5(tree[, space])`
5895

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

6198
###### `space`
6299

63-
Whether the root of the given [*tree*][tree] is in the `'html'` or `'svg'` space
64-
(enum, `'svg'` or `'html'`, default: `'html'`).
100+
Whether the root of the given tree is in the HTML or SVG space (enum, `'svg'` or
101+
`'html'`, default: `'html'`).
65102

66103
If an `svg` element is found in the HTML space, `toParse5` automatically
67104
switches to the SVG space when entering the element, and switches back when
68105
exiting.
69106

107+
## Types
108+
109+
This package is fully typed with [TypeScript][].
110+
It exports the additional type `Space`.
111+
112+
## Compatibility
113+
114+
Projects maintained by the unified collective are compatible with all maintained
115+
versions of Node.js.
116+
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
117+
Our projects sometimes work with older versions, but this is not guaranteed.
118+
70119
## Security
71120

72121
Use of `hast-util-to-parse5` can open you up to a
@@ -89,8 +138,8 @@ Use of `hast-util-to-parse5` can open you up to a
89138

90139
## Contribute
91140

92-
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
93-
started.
141+
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
142+
ways to get started.
94143
See [`support.md`][support] for ways to get help.
95144

96145
This project has a [code of conduct][coc].
@@ -131,20 +180,30 @@ abide by its terms.
131180

132181
[npm]: https://docs.npmjs.com/cli/install
133182

183+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
184+
185+
[esmsh]: https://esm.sh
186+
187+
[typescript]: https://www.typescriptlang.org
188+
134189
[license]: license
135190

136191
[author]: https://wooorm.com
137192

138-
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
193+
[health]: https://github.com/syntax-tree/.github
139194

140-
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
195+
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
141196

142-
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
197+
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
143198

144-
[ast]: https://github.com/inikulin/parse5/wiki/Documentation
145-
146-
[tree]: https://github.com/syntax-tree/unist#tree
199+
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
147200

148201
[hast]: https://github.com/syntax-tree/hast
149202

150203
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
204+
205+
[parse5]: https://github.com/inikulin/parse5
206+
207+
[ast]: https://github.com/inikulin/parse5/wiki/Documentation
208+
209+
[hast-util-from-parse5]: https://github.com/syntax-tree/hast-util-from-parse5

0 commit comments

Comments
 (0)