1717* [ Install] ( #install )
1818* [ Use] ( #use )
1919* [ API] ( #api )
20- * [ ` toc(node[, options]) ` ] ( #tocnode-options )
20+ * [ ` toc(tree[, options]) ` ] ( #toctree-options )
21+ * [ ` Options ` ] ( #options )
22+ * [ ` Result ` ] ( #result )
2123* [ Types] ( #types )
2224* [ Compatibility] ( #compatibility )
2325* [ Security] ( #security )
@@ -40,7 +42,7 @@ This package is wrapped in [`remark-toc`][remark-toc] for ease of use with
4042## Install
4143
4244This package is [ ESM only] [ esm ] .
43- In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
45+ In Node.js (version 14.14+ and 16.0+), install with [ npm] [ ] :
4446
4547``` sh
4648npm install mdast-util-toc
@@ -105,12 +107,12 @@ Yields:
105107
106108## API
107109
108- This package exports the identifier ` toc ` .
110+ This package exports the identifier [ ` toc ` ] [ api-toc ] .
109111There is no default export.
110112
111- ### ` toc(node [, options]) `
113+ ### ` toc(tree [, options]) `
112114
113- Generate a table of contents from [ ` node ` ] [ node ] .
115+ Generate a table of contents from ` tree ` .
114116
115117Looks for the first heading matching ` options.heading ` (case insensitive) and
116118returns a table of contents (a list) for all following headings.
@@ -120,87 +122,77 @@ If no `heading` is specified, creates a table of contents for all headings in
120122
121123Links in the list to headings are based on GitHub’s style.
122124Only top-level headings (those not in blockquotes or lists), are used.
123- This default behavior can be changed by passing [ ` options.parents ` ] [ parents ] .
124-
125- ##### ` options `
126-
127- Configuration (optional).
128-
129- ###### ` options.heading `
130-
131- [ Heading] [ ] to look for (` string ` ), wrapped in `new RegExp('^(' + value + ')$',
132- 'i')`.
133-
134- ###### ` options.maxDepth `
135-
136- Maximum heading depth to include in the table of contents (` number ` , default:
137- ` 6 ` ),
138- This is inclusive: when set to ` 3 ` , level three headings are included (those
139- with three hashes, ` ### ` ).
140-
141- ###### ` options.skip `
142-
143- Headings to skip (` string ` , optional), wrapped in
144- ` new RegExp('^(' + value + ')$', 'i') ` .
145- Any heading matching this expression will not be present in the table of
146- contents.
147-
148- ###### ` options.tight `
149-
150- Whether to compile list items tightly (` boolean? ` , default: ` false ` ).
151-
152- ###### ` options.ordered `
153-
154- Whether to compile list items as an ordered list (` boolean? ` , default: ` false ` ).
155-
156- ###### ` options.prefix `
157-
158- Add a prefix to links to headings in the table of contents (` string? ` , default:
159- ` null ` ).
160- Useful for example when later going from [ mdast] [ ] to [ hast] [ ] and sanitizing
161- with [ ` hast-util-sanitize ` ] [ sanitize ] .
162-
163- ###### ` options.parents `
164-
165- Allow headings to be children of certain node types (default: the to ` toc ` given
166- ` node ` , to only allow top-level headings).
167- Internally, uses [ ` unist-util-is ` ] [ is ] , so ` parents ` can be any
168- ` is ` -compatible test.
169-
170- For example, the following code would allow headings under either ` root ` or
171- ` blockquote ` to be used:
172-
173- ``` js
174- toc (tree, {parents: [' root' , ' blockquote' ]})
175- ```
176-
177- ##### Returns
178-
179- An object representing the table of contents:
180-
181- * ` index ` (` number? ` )
182- — index of the node right after the table of contents [ heading] [ ] .
183- ` -1 ` if no heading was found, ` null ` if no ` heading ` was given
184- * ` endIndex ` (` number? ` )
185- — index of the first node after ` heading ` that is not part of its section.
125+ This default behavior can be changed by passing ` options.parents ` .
126+
127+ ###### Parameters
128+
129+ * ` tree ` ([ ` Node ` ] [ node ] )
130+ — tree to search and generate from
131+ * ` options ` ([ ` Options ` ] [ api-options ] , optional)
132+ — configuration
133+
134+ ###### Returns
135+
136+ Results ([ ` Result ` ] [ api-result ] ).
137+
138+ ### ` Options `
139+
140+ Configuration (TypeScript type).
141+
142+ ###### Fields
143+
144+ * ` heading ` (` string ` , optional)
145+ — heading to look for, wrapped in ` new RegExp('^(' + value + ')$', 'i') `
146+ * ` maxDepth ` (` number ` , default: ` 6 ` )
147+ — maximum heading depth to include in the table of contents.
148+ This is inclusive: when set to ` 3 ` , level three headings are included
149+ (those with three hashes, ` ### ` )
150+ * ` skip ` (` string ` , optional)
151+ — headings to skip, wrapped in ` new RegExp('^(' + value + ')$', 'i') ` .
152+ Any heading matching this expression will not be present in the table of
153+ contents
154+ * ` parents ` ([ ` Test ` ] [ test ] , default: ` tree ` )
155+ — allow headings to be children of certain node types.
156+ Can by any [ ` unist-util-is ` ] [ is ] compatible test
157+ * ` tight ` (` boolean ` , default: ` false ` )
158+ — whether to compile list items tightly
159+ * ` ordered ` (` boolean ` , default: ` false ` )
160+ — whether to compile list items as an ordered list, otherwise they are
161+ unordered
162+ * ` prefix ` (` string ` , optional)
163+ — add a prefix to links to headings in the table of contents.
164+ Useful for example when later going from mdast to hast and sanitizing with
165+ ` hast-util-sanitize ` .
166+
167+ ### ` Result `
168+
169+ Results (TypeScript type).
170+
171+ ###### Fields
172+
173+ * ` index ` (` number ` or ` null ` )
174+ — index of the node right after the table of contents heading, ` -1 ` if no
175+ heading was found, ` null ` if no ` heading ` was given
176+ * ` endIndex ` (` number ` or ` null ` )
177+ — index of the first node after ` heading ` that is not part of its section,
186178 ` -1 ` if no heading was found, ` null ` if no ` heading ` was given, same as
187- ` index ` if there are no nodes between ` heading ` and the first heading in the
188- table of contents
189- * ` map ` (` Node? ` )
190- — list representing the generated table of contents.
191- ` null ` if no table of contents could be created, either because no heading
192- was found or because no following headings were found
179+ ` index ` if there are no nodes between ` heading ` and the first heading in
180+ the table of contents
181+ * ` map ` ([ ` List ` ] [ list ] or ` null ` )
182+ — list representing the generated table of contents, ` null ` if no table of
183+ contents could be created, either because no heading was found or because
184+ no following headings were found
193185
194186## Types
195187
196188This package is fully typed with [ TypeScript] [ ] .
197- It exports the types ` Options ` and ` Result ` .
189+ It exports the types [ ` Options ` ] [ api-options ] and [ ` Result ` ] [ api-result ] .
198190
199191## Compatibility
200192
201193Projects maintained by the unified collective are compatible with all maintained
202194versions of Node.js.
203- As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
195+ As of now, that is Node.js 14.14+ and 16.0+.
204196Our projects sometimes work with older versions, but this is not guaranteed.
205197
206198## Security
@@ -313,14 +305,20 @@ abide by its terms.
313305
314306[ is ] : https://github.com/syntax-tree/unist-util-is
315307
316- [ heading ] : https://github.com/syntax-tree/mdast#heading
308+ [ list ] : https://github.com/syntax-tree/mdast#list
317309
318310[ node ] : https://github.com/syntax-tree/mdast#node
319311
320- [ parents ] : #optionsparents
321-
322312[ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
323313
324314[ remark ] : https://github.com/remarkjs/remark
325315
326316[ remark-toc ] : https://github.com/remarkjs/remark-toc
317+
318+ [ test ] : https://github.com/syntax-tree/unist-util-is#test
319+
320+ [ api-toc ] : #toctree-options
321+
322+ [ api-options ] : #options
323+
324+ [ api-result ] : #result
0 commit comments