|
18 | 18 | * [Use](#use) |
19 | 19 | * [API](#api) |
20 | 20 | * [`zone(tree, name, handler)`](#zonetree-name-handler) |
| 21 | + * [`Handler`](#handler) |
| 22 | + * [`ZoneInfo`](#zoneinfo) |
21 | 23 | * [Types](#types) |
22 | 24 | * [Compatibility](#compatibility) |
23 | 25 | * [Security](#security) |
@@ -45,7 +47,7 @@ the same but uses a heading to mark the start and end of sections. |
45 | 47 | ## Install |
46 | 48 |
|
47 | 49 | This package is [ESM only][esm]. |
48 | | -In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: |
| 50 | +In Node.js (version 14.14+ and 16.0+), install with [npm][]: |
49 | 51 |
|
50 | 52 | ```sh |
51 | 53 | npm install mdast-zone |
@@ -114,57 +116,74 @@ Bar. |
114 | 116 |
|
115 | 117 | ## API |
116 | 118 |
|
117 | | -This package exports the identifier `zone`. |
| 119 | +This package exports the identifier [`zone`][api-zone]. |
118 | 120 | There is no default export. |
119 | 121 |
|
120 | 122 | ### `zone(tree, name, handler)` |
121 | 123 |
|
122 | | -Search `tree` ([`Node`][node]) for comments marked `name` (`string`) and |
123 | | -transform a section with `handler` ([`Function`][handler]). |
| 124 | +Search `tree` for a start and end comments matching `name` and change their |
| 125 | +“section” with `handler`. |
124 | 126 |
|
125 | | -#### `function handler(start, nodes, end, info)` |
| 127 | +###### Parameters |
126 | 128 |
|
127 | | -Callback called when a range is found. |
| 129 | +* `tree` ([`Node`][node]) |
| 130 | + — tree to change |
| 131 | +* `name` (`string`) |
| 132 | + — comment name to look for |
| 133 | +* `handler` ([`Handler`][api-handler]) |
| 134 | + — handle a section |
128 | 135 |
|
129 | | -##### Parameters |
| 136 | +###### Returns |
130 | 137 |
|
131 | | -Arguments. |
| 138 | +Nothing (`void`). |
132 | 139 |
|
133 | | -###### `start` |
| 140 | +### `Handler` |
134 | 141 |
|
135 | | -Start of range ([`Node`][node]), an [HTML][] (or MDX) comment node. |
| 142 | +Callback called when a section is found (TypeScript type). |
136 | 143 |
|
137 | | -###### `nodes` |
| 144 | +###### Parameters |
138 | 145 |
|
139 | | -Nodes between `start` and `end` ([`Array<Node>`][node]). |
| 146 | +* `start` ([`Node`][node]) |
| 147 | + — start of section |
| 148 | +* `nodes` ([`Array<Node>`][node]) |
| 149 | + — nodes between `start` and `end` |
| 150 | +* `end` ([`Node`][node]) |
| 151 | + — end of section |
| 152 | +* `info` ([`ZoneInfo`][api-zoneinfo]) |
| 153 | + — extra info |
140 | 154 |
|
141 | | -###### `end` |
| 155 | +###### Returns |
142 | 156 |
|
143 | | -End of range ([`Node`][node]), an [HTML][] (or MDX) comment node. |
| 157 | +Results (`Array<Node | null | undefined>`, optional). |
144 | 158 |
|
145 | | -###### `info` |
| 159 | +If nothing is returned, nothing will be changed. |
| 160 | +If an array of nodes (can include `null` and `undefined`) is returned, the |
| 161 | +original section will be replaced by those nodes. |
146 | 162 |
|
147 | | -Extra info (`Object`): |
| 163 | +### `ZoneInfo` |
148 | 164 |
|
149 | | -* `parent` ([`Node`][node]) — parent of the range |
150 | | -* `start` (`number`) — index of `start` in `parent` |
151 | | -* `end` (`number`) — index of `end` in `parent` |
| 165 | +Extra info (TypeScript type). |
152 | 166 |
|
153 | | -###### Returns |
| 167 | +###### Fields |
154 | 168 |
|
155 | | -Optional list of nodes to replace `start`, `nodes`, and `end` with |
156 | | -([`Array<Node>?`][node]). |
| 169 | +* `parent` ([`Node`][node]) |
| 170 | + — parent of the section |
| 171 | +* `start` (`number`) |
| 172 | + — index of `start` in `parent` |
| 173 | +* `end` (`number` or `null`) |
| 174 | + — index of `end` in `parent` |
157 | 175 |
|
158 | 176 | ## Types |
159 | 177 |
|
160 | 178 | This package is fully typed with [TypeScript][]. |
161 | | -This package exports the types `Handler` and `ZoneInfo`. |
| 179 | +It exports the additional types [`Handler`][api-handler] and |
| 180 | +[`ZoneInfo`][api-zoneinfo]. |
162 | 181 |
|
163 | 182 | ## Compatibility |
164 | 183 |
|
165 | 184 | Projects maintained by the unified collective are compatible with all maintained |
166 | 185 | versions of Node.js. |
167 | | -As of now, that is Node.js 12.20+, 14.14+, and 16.0+. |
| 186 | +As of now, that is Node.js 14.14+ and 16.0+. |
168 | 187 | Our projects sometimes work with older versions, but this is not guaranteed. |
169 | 188 |
|
170 | 189 | ## Security |
@@ -266,12 +285,14 @@ abide by its terms. |
266 | 285 |
|
267 | 286 | [node]: https://github.com/syntax-tree/mdast#nodes |
268 | 287 |
|
269 | | -[html]: https://github.com/syntax-tree/mdast#html |
270 | | - |
271 | 288 | [mdast-util-heading-range]: https://github.com/syntax-tree/mdast-util-heading-range |
272 | 289 |
|
273 | 290 | [hast]: https://github.com/syntax-tree/hast |
274 | 291 |
|
275 | 292 | [hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize |
276 | 293 |
|
277 | | -[handler]: #function-handlerstart-nodes-end-info |
| 294 | +[api-zone]: #zonetree-name-handler |
| 295 | + |
| 296 | +[api-handler]: #handler |
| 297 | + |
| 298 | +[api-zoneinfo]: #zoneinfo |
0 commit comments