18
18
* [ Use] ( #use )
19
19
* [ API] ( #api )
20
20
* [ ` headingRange(tree, test|options, handler) ` ] ( #headingrangetree-testoptions-handler )
21
+ * [ ` Handler ` ] ( #handler )
22
+ * [ ` Options ` ] ( #options )
23
+ * [ ` Test ` ] ( #test )
24
+ * [ ` TestFunction ` ] ( #testfunction )
25
+ * [ ` ZoneInfo ` ] ( #zoneinfo )
21
26
* [ Types] ( #types )
22
27
* [ Compatibility] ( #compatibility )
23
28
* [ Security] ( #security )
@@ -45,7 +50,7 @@ to mark the start and end of sections.
45
50
## Install
46
51
47
52
This package is [ ESM only] [ esm ] .
48
- In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
53
+ In Node.js (version 14.14+ and 16.0+), install with [ npm] [ ] :
49
54
50
55
``` sh
51
56
npm install mdast-util-heading-range
@@ -114,77 +119,122 @@ Qux.
114
119
115
120
## API
116
121
117
- This package exports the identifier ` headingRange ` .
122
+ This package exports the identifier [ ` headingRange ` ] [ api-headingrange ] .
118
123
There is no default export.
119
124
120
125
### ` headingRange(tree, test|options, handler) `
121
126
122
- Search ` tree ` ( [ ` Node ` ] [ node ] ) and transform a section with ` handler `
123
- ( [ ` Function ` ] [ handler ] ) .
127
+ Search ` tree ` for a heading matching ` test ` and change its “ section” with
128
+ ` handler ` .
124
129
125
- ##### ` options `
130
+ A “section” ranges from the matched heading until the next heading of the
131
+ same or lower depth, or the end of the document.
126
132
127
- Configuration (optional).
133
+ If ` ignoreFinalDefinitions: true ` , final definitions “in” the section are
134
+ excluded.
128
135
129
- ###### ` options.test `
136
+ ###### Parameters
130
137
131
- Heading to look for (` string ` , ` RegExp ` , [ ` Function ` ] [ test ] ).
132
- When ` string ` , wrapped in ` new RegExp('^(' + value + ')$', 'i') ` ;
133
- when ` RegExp ` , wrapped in ` function (value) {expression.test(value)} `
138
+ * ` tree ` ([ ` Node ` ] [ node ] )
139
+ — tree to change
140
+ * ` test ` ([ ` Test ` ] [ api-test ] )
141
+ — same as passing ` {test: Test} `
142
+ * ` options ` ([ ` Options ` ] [ api-options ] )
143
+ — configuration
144
+ * ` handler ` ([ ` Handler ` ] [ api-handler ] )
145
+ — handle a section
146
+
147
+ ###### Returns
134
148
135
- ###### ` options.ignoreFinalDefinitions `
149
+ Nothing ( ` void ` ).
136
150
137
- Ignore trailing definitions otherwise in the section (` boolean ` , default:
138
- ` false ` ).
151
+ ### ` Handler `
139
152
140
- #### ` function test(value, node) `
153
+ Callback called when a section is found (TypeScript type).
141
154
142
- Function called for each heading with its content (` string ` ) and ` node `
143
- itself ([ ` Heading ` ] [ heading ] ) to check if it’s the one to look for.
155
+ ###### Parameters
156
+
157
+ * ` start ` ([ ` Heading ` ] [ heading ] )
158
+ — start of section (a heading node matching ` test ` )
159
+ * ` nodes ` ([ ` Array<Node> ` ] [ node ] )
160
+ — nodes between ` start ` and ` end `
161
+ * ` end ` ([ ` Node ` ] [ node ] or ` undefined ` )
162
+ — end of section, if any
163
+ * ` info ` ([ ` ZoneInfo ` ] [ api-zoneinfo ] )
164
+ — extra info
144
165
145
166
###### Returns
146
167
147
- Whether to use this heading (` boolean ` ).
168
+ Results (` Array<Node | null | undefined> ` , optional).
169
+
170
+ If nothing is returned, nothing will be changed.
171
+ If an array of nodes (can include ` null ` and ` undefined ` ) is returned, the
172
+ original section will be replaced by those nodes.
173
+
174
+ ### ` Options `
175
+
176
+ Configuration (TypeScript type).
177
+
178
+ ###### Fields
179
+
180
+ * ` test ` ([ ` Test ` ] [ api-test ] )
181
+ — test for a heading
182
+ * ` ignoreFinalDefinitions ` (` boolean ` , default: ` false ` )
183
+ — ignore final definitions otherwise in the section
184
+
185
+ ### ` Test `
186
+
187
+ Test for a heading (TypeScript type).
148
188
149
- #### ` function handler(start, nodes, end, info) `
189
+ When ` string ` , wrapped in ` new RegExp('^(' + value + ')$', 'i') ` ;
190
+ when ` RegExp ` , wrapped in ` (value) => expression.test(value) `
150
191
151
- Callback called when a range is found.
192
+ ###### Type
152
193
153
- ##### Parameters
194
+ ``` ts
195
+ export type Test = string | RegExp | TestFunction
196
+ ` ` `
154
197
155
- Arguments.
198
+ ### ` TestFunction `
156
199
157
- ###### ` start `
200
+ Check if a node matches (TypeScript type).
158
201
159
- Start of range ( [ ` Heading ` ] [ heading ] ).
202
+ ###### Parameters
160
203
161
- ###### ` nodes `
204
+ * ` value ` ( ` string ` )
205
+ — plain-text heading
206
+ * ` node ` ([ ` Heading ` ][heading])
207
+ — heading node
162
208
163
- Nodes between ` start ` and ` end ` ( [ ` Array<Node> ` ] [ node ] ).
209
+ ###### Returns
164
210
165
- ###### ` end `
211
+ Whether this is the heading that is searched for ( ` boolean ` , optional).
166
212
167
- End of range, if any ( [ ` Node? ` ] [ node ] ).
213
+ ### ` ZoneInfo `
168
214
169
- ###### ` info `
215
+ Extra info (TypeScript type).
170
216
171
- Extra info ( ` Object ` ):
217
+ ###### Fields
172
218
173
- * ` parent ` ([ ` Node ` ] [ node ] ) — parent of the range
174
- * ` start ` (` number ` ) — index of ` start ` in ` parent `
175
- * ` end ` (` number? ` ) — index of ` end ` in ` parent `
219
+ * ` parent ` ([ ` Node ` ][node])
220
+ — parent of the section
221
+ * ` start ` ( ` number ` )
222
+ — index of ` start ` in ` parent `
223
+ * ` end ` ( ` number ` or ` null ` )
224
+ — index of ` end ` in ` parent `
176
225
177
226
## Types
178
227
179
228
This package is fully typed with [TypeScript][].
180
- This package exports the types ` Handler ` , ` Options ` , ` TestFunction ` , ` Test ` ,
181
- and ` ZoneInfo ` .
229
+ This package exports the types [ ` Handler ` ][api-handler],
230
+ [ ` Options ` ][api-options], [ ` Test ` ][api-test],
231
+ [ ` TestFunction ` ][api-testfunction], and [ ` ZoneInfo ` ][api-zoneinfo].
182
232
183
233
## Compatibility
184
234
185
235
Projects maintained by the unified collective are compatible with all maintained
186
236
versions of Node.js.
187
- As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
237
+ As of now, that is Node.js 14.14+ and 16.0+.
188
238
Our projects sometimes work with older versions, but this is not guaranteed.
189
239
190
240
## Security
@@ -286,12 +336,8 @@ abide by its terms.
286
336
287
337
[ node ] : https://github.com/syntax-tree/unist#node
288
338
289
- [ handler ] : #function-handlerstart-nodes-end-info
290
-
291
339
[ heading ] : https://github.com/syntax-tree/mdast#heading
292
340
293
- [ test ] : #function-testvalue-node
294
-
295
341
[ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
296
342
297
343
[ hast ] : https://github.com/syntax-tree/hast
@@ -301,3 +347,15 @@ abide by its terms.
301
347
[ hast-util-sanitize ] : https://github.com/syntax-tree/hast-util-sanitize
302
348
303
349
[ remark-toc ] : https://github.com/remarkjs/remark-toc
350
+
351
+ [ api-headingrange ] : #headingrangetree-testoptions-handler
352
+
353
+ [ api-handler ] : #handler
354
+
355
+ [ api-options ] : #options
356
+
357
+ [ api-test ] : #test
358
+
359
+ [ api-testfunction ] : #testfunction
360
+
361
+ [ api-zoneinfo ] : #zoneinfo
0 commit comments