1818* [ Use] ( #use )
1919* [ API] ( #api )
2020 * [ ` headingRange(tree, test|options, handler) ` ] ( #headingrangetree-testoptions-handler )
21+ * [ ` Handler ` ] ( #handler )
22+ * [ ` Options ` ] ( #options )
23+ * [ ` Test ` ] ( #test )
24+ * [ ` TestFunction ` ] ( #testfunction )
25+ * [ ` ZoneInfo ` ] ( #zoneinfo )
2126* [ Types] ( #types )
2227* [ Compatibility] ( #compatibility )
2328* [ Security] ( #security )
@@ -45,7 +50,7 @@ to mark the start and end of sections.
4550## Install
4651
4752This 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] [ ] :
4954
5055``` sh
5156npm install mdast-util-heading-range
@@ -114,77 +119,122 @@ Qux.
114119
115120## API
116121
117- This package exports the identifier ` headingRange ` .
122+ This package exports the identifier [ ` headingRange ` ] [ api-headingrange ] .
118123There is no default export.
119124
120125### ` headingRange(tree, test|options, handler) `
121126
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 ` .
124129
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.
126132
127- Configuration (optional).
133+ If ` ignoreFinalDefinitions: true ` , final definitions “in” the section are
134+ excluded.
128135
129- ###### ` options.test `
136+ ###### Parameters
130137
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
134148
135- ###### ` options.ignoreFinalDefinitions `
149+ Nothing ( ` void ` ).
136150
137- Ignore trailing definitions otherwise in the section (` boolean ` , default:
138- ` false ` ).
151+ ### ` Handler `
139152
140- #### ` function test(value, node) `
153+ Callback called when a section is found (TypeScript type).
141154
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
144165
145166###### Returns
146167
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).
148188
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) `
150191
151- Callback called when a range is found.
192+ ###### Type
152193
153- ##### Parameters
194+ ``` ts
195+ export type Test = string | RegExp | TestFunction
196+ ` ` `
154197
155- Arguments.
198+ ### ` TestFunction `
156199
157- ###### ` start `
200+ Check if a node matches (TypeScript type).
158201
159- Start of range ( [ ` Heading ` ] [ heading ] ).
202+ ###### Parameters
160203
161- ###### ` nodes `
204+ * ` value ` ( ` string ` )
205+ — plain-text heading
206+ * ` node ` ([ ` Heading ` ][heading])
207+ — heading node
162208
163- Nodes between ` start ` and ` end ` ( [ ` Array<Node> ` ] [ node ] ).
209+ ###### Returns
164210
165- ###### ` end `
211+ Whether this is the heading that is searched for ( ` boolean ` , optional).
166212
167- End of range, if any ( [ ` Node? ` ] [ node ] ).
213+ ### ` ZoneInfo `
168214
169- ###### ` info `
215+ Extra info (TypeScript type).
170216
171- Extra info ( ` Object ` ):
217+ ###### Fields
172218
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 `
176225
177226## Types
178227
179228This 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].
182232
183233## Compatibility
184234
185235Projects maintained by the unified collective are compatible with all maintained
186236versions 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+.
188238Our projects sometimes work with older versions, but this is not guaranteed.
189239
190240## Security
@@ -286,12 +336,8 @@ abide by its terms.
286336
287337[ node ] : https://github.com/syntax-tree/unist#node
288338
289- [ handler ] : #function-handlerstart-nodes-end-info
290-
291339[ heading ] : https://github.com/syntax-tree/mdast#heading
292340
293- [ test ] : #function-testvalue-node
294-
295341[ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
296342
297343[ hast ] : https://github.com/syntax-tree/hast
@@ -301,3 +347,15 @@ abide by its terms.
301347[ hast-util-sanitize ] : https://github.com/syntax-tree/hast-util-sanitize
302348
303349[ 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