Skip to content

Commit 46a4e51

Browse files
committed
Add improved docs
1 parent 23da80e commit 46a4e51

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

Diff for: readme.md

+46-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`fromDom(node, options?)`](#fromdomnode-options)
20+
* [`fromDom(tree, options?)`](#fromdomtree-options)
21+
* [`AfterTransform`](#aftertransform)
22+
* [`Options`](#options)
2123
* [Types](#types)
2224
* [Compatibility](#compatibility)
2325
* [Security](#security)
@@ -50,7 +52,7 @@ parse HTML with DOM APIs.
5052
## Install
5153

5254
This package is [ESM only][esm].
53-
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
55+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
5456

5557
```sh
5658
npm install hast-util-from-dom
@@ -99,21 +101,47 @@ Now running `open example.html` prints the following to the console:
99101

100102
## API
101103

102-
This package exports the identifier `fromDom`.
104+
This package exports the identifier [`fromDom`][fromdom].
103105
There is no default export.
104106

105-
### `fromDom(node, options?)`
107+
### `fromDom(tree, options?)`
106108

107-
Turn a DOM tree into a hast tree.
109+
Transform a DOM tree to a hast tree.
108110

109-
##### options
111+
###### Parameters
110112

111-
Configuration (optional).
113+
* `tree` ([`DomNode`][dom-node])
114+
— DOM tree to transform
115+
* `options` ([`Options`][options], optional)
116+
— configuration
112117

113-
###### `options.afterTransform`
118+
###### Returns
114119

115-
Called when a DOM node was transformed into a hast node
116-
(`(Node, HastNode) => void?`).
120+
Equivalent hast node ([`HastNode`][hast-node]).
121+
122+
### `AfterTransform`
123+
124+
Callback called when each node is transformed (TypeScript type).
125+
126+
###### Parameters
127+
128+
* `domNode` ([`DomNode`][dom-node])
129+
— DOM node that was handled
130+
* `hastNode` ([`HastNode`][hast-node])
131+
— corresponding hast node
132+
133+
###### Returns
134+
135+
Nothing.
136+
137+
### `Options`
138+
139+
Configuration (TypeScript type).
140+
141+
##### Fields
142+
143+
* `afterTransform` ([`AfterTransform`][aftertransform], optional)
144+
— callback called when each node is transformed
117145

118146
##### Returns
119147

@@ -215,10 +243,18 @@ abide by its terms.
215243

216244
[dom]: https://developer.mozilla.org/docs/Web/API/Document_Object_Model
217245

246+
[dom-node]: https://developer.mozilla.org/docs/Web/API/Node
247+
218248
[hast-util-from-html]: https://github.com/syntax-tree/hast-util-from-html
219249

220250
[hast-util-to-dom]: https://github.com/syntax-tree/hast-util-to-dom
221251

222252
[rehype-dom-parse]: https://github.com/rehypejs/rehype-dom/tree/main/packages/rehype-dom-parse
223253

224254
[jsdom]: https://github.com/jsdom/jsdom
255+
256+
[fromdom]: #fromdomtree-options
257+
258+
[options]: #options
259+
260+
[aftertransform]: #aftertransform

0 commit comments

Comments
 (0)