Skip to content

Commit 2ff6c95

Browse files
committed
Add improved docs
1 parent b83ec5f commit 2ff6c95

File tree

2 files changed

+54
-22
lines changed

2 files changed

+54
-22
lines changed

Diff for: lib/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
* @typedef Options
3030
* Configuration.
3131
* @property {Array<string> | null | undefined} [passThrough]
32-
* List of custom hast node types to pass through (keep) in hast.
32+
* List of custom hast node types to pass through (keep).
3333
*
3434
* If the passed through nodes have children, those children are expected to
3535
* be hast again and will be handled.
3636
* @property {VFile | null | undefined} [file]
37-
* Corresponding virtual file.
37+
* Corresponding virtual file representing the input document.
3838
*
3939
* @typedef State
4040
* Info passed around about the current state.
@@ -72,8 +72,8 @@ const knownMdxNames = new Set([
7272
const parseOptions = {sourceCodeLocationInfo: true, scriptingEnabled: false}
7373

7474
/**
75-
* Pass a hast tree through an HTML parser, which will fix nesting, and
76-
* turn raw nodes into actual nodes.
75+
* Pass a hast tree through an HTML parser, which will fix nesting, and turn
76+
* raw nodes into actual nodes.
7777
*
7878
* @param {Node} tree
7979
* Original hast tree to transform.

Diff for: readme.md

+50-18
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ HTML) again, keeping positional info okay.
1818
* [Install](#install)
1919
* [Use](#use)
2020
* [API](#api)
21-
* [`raw(tree[, file][, options])`](#rawtree-file-options)
21+
* [`raw(tree[, options])`](#rawtree-options)
22+
* [`Options`](#options)
23+
* [`Raw`](#raw)
2224
* [Types](#types)
2325
* [Compatibility](#compatibility)
2426
* [Security](#security)
@@ -63,7 +65,7 @@ The plugin [`rehype-raw`][rehype-raw] wraps this utility at a higher-level
6365
## Install
6466

6567
This package is [ESM only][esm].
66-
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
68+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
6769

6870
```sh
6971
npm install hast-util-raw
@@ -116,34 +118,56 @@ Yields:
116118

117119
## API
118120

119-
This package exports the identifier `raw`.
121+
This package exports the identifier [`raw`][raw].
120122
There is no default export.
121123

122-
### `raw(tree[, file][, options])`
124+
### `raw(tree[, options])`
123125

124-
Parse the tree and raw nodes (strings of HTML) again, keeping positional info
125-
okay.
126+
Pass a hast tree through an HTML parser, which will fix nesting, and turn raw
127+
nodes into actual nodes.
126128

127-
> 👉 **Note**: `tree` should have positional info and `file`, when given, must
128-
> be a [vfile][] corresponding to `tree`.
129+
###### Parameters
129130

130-
##### `options`
131+
* `tree` ([`Node`][node])
132+
— original hast tree to transform
133+
* `options` ([`Options`][options], optional)
134+
— configuration
131135

132-
Configuration (optional).
136+
###### Returns
133137

134-
###### `options.passThrough`
138+
Parsed again tree ([`Node`][node]).
135139

136-
List of custom hast node types to pass through (keep) in hast (`Array<string>`,
137-
default: `[]`).
138-
If the passed through nodes have children, those children are expected to be
139-
hast and will be handled by this utility.
140+
### `Options`
141+
142+
Configuration (TypeScript type).
143+
144+
###### Fields
145+
146+
* `passThrough` (`Array<string>`, optional)
147+
— list of custom hast node types to pass through (keep).
148+
If the passed through nodes have children, those children are expected to be
149+
hast and will be handled by this utility
150+
* `file` ([`VFile`][vfile], optional)
151+
— corresponding virtual file representing the input document
152+
153+
### `Raw`
154+
155+
Interface of semistandard `Raw` nodes (TypeScript type).
156+
157+
###### Type
158+
159+
```ts
160+
export interface Raw extends Literal {
161+
type: 'raw'
162+
}
163+
```
140164

141165
## Types
142166

143167
This package is fully typed with [TypeScript][].
144-
It exports the additional type `Options`.
168+
It exports the additional types [`Options`][options] and [`Raw`][raw-node].
145169

146-
It also registers the `Raw` node type with `@types/hast`.
170+
The types also register the `Raw` node type with `@types/hast`.
147171
If you’re working with the syntax tree, make sure to import this utility
148172
somewhere in your types, as that registers the new node types in the tree.
149173

@@ -166,7 +190,7 @@ visit(tree, (node) => {
166190

167191
Projects maintained by the unified collective are compatible with all maintained
168192
versions of Node.js.
169-
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
193+
As of now, that is Node.js 14.14+ and 16.0+.
170194
Our projects sometimes work with older versions, but this is not guaranteed.
171195

172196
## Security
@@ -262,10 +286,18 @@ abide by its terms.
262286

263287
[hast]: https://github.com/syntax-tree/hast
264288

289+
[node]: https://github.com/syntax-tree/hast#nodes
290+
265291
[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize
266292

267293
[vfile]: https://github.com/vfile/vfile
268294

269295
[rehype-raw]: https://github.com/rehypejs/rehype-raw
270296

271297
[parse5]: https://github.com/inikulin/parse5
298+
299+
[raw]: #rawtree-options
300+
301+
[options]: #options
302+
303+
[raw-node]: #raw

0 commit comments

Comments
 (0)