|
17 | 17 | * [Install](#install)
|
18 | 18 | * [Use](#use)
|
19 | 19 | * [API](#api)
|
20 |
| - * [`fromDom(node, options?)`](#fromdomnode-options) |
| 20 | + * [`fromDom(tree, options?)`](#fromdomtree-options) |
| 21 | + * [`AfterTransform`](#aftertransform) |
| 22 | + * [`Options`](#options) |
21 | 23 | * [Types](#types)
|
22 | 24 | * [Compatibility](#compatibility)
|
23 | 25 | * [Security](#security)
|
@@ -50,7 +52,7 @@ parse HTML with DOM APIs.
|
50 | 52 | ## Install
|
51 | 53 |
|
52 | 54 | 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][]: |
54 | 56 |
|
55 | 57 | ```sh
|
56 | 58 | npm install hast-util-from-dom
|
@@ -99,21 +101,47 @@ Now running `open example.html` prints the following to the console:
|
99 | 101 |
|
100 | 102 | ## API
|
101 | 103 |
|
102 |
| -This package exports the identifier `fromDom`. |
| 104 | +This package exports the identifier [`fromDom`][fromdom]. |
103 | 105 | There is no default export.
|
104 | 106 |
|
105 |
| -### `fromDom(node, options?)` |
| 107 | +### `fromDom(tree, options?)` |
106 | 108 |
|
107 |
| -Turn a DOM tree into a hast tree. |
| 109 | +Transform a DOM tree to a hast tree. |
108 | 110 |
|
109 |
| -##### options |
| 111 | +###### Parameters |
110 | 112 |
|
111 |
| -Configuration (optional). |
| 113 | +* `tree` ([`DomNode`][dom-node]) |
| 114 | + — DOM tree to transform |
| 115 | +* `options` ([`Options`][options], optional) |
| 116 | + — configuration |
112 | 117 |
|
113 |
| -###### `options.afterTransform` |
| 118 | +###### Returns |
114 | 119 |
|
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 |
117 | 145 |
|
118 | 146 | ##### Returns
|
119 | 147 |
|
@@ -215,10 +243,18 @@ abide by its terms.
|
215 | 243 |
|
216 | 244 | [dom]: https://developer.mozilla.org/docs/Web/API/Document_Object_Model
|
217 | 245 |
|
| 246 | +[dom-node]: https://developer.mozilla.org/docs/Web/API/Node |
| 247 | + |
218 | 248 | [hast-util-from-html]: https://github.com/syntax-tree/hast-util-from-html
|
219 | 249 |
|
220 | 250 | [hast-util-to-dom]: https://github.com/syntax-tree/hast-util-to-dom
|
221 | 251 |
|
222 | 252 | [rehype-dom-parse]: https://github.com/rehypejs/rehype-dom/tree/main/packages/rehype-dom-parse
|
223 | 253 |
|
224 | 254 | [jsdom]: https://github.com/jsdom/jsdom
|
| 255 | + |
| 256 | +[fromdom]: #fromdomtree-options |
| 257 | + |
| 258 | +[options]: #options |
| 259 | + |
| 260 | +[aftertransform]: #aftertransform |
0 commit comments