17
17
* [ Install] ( #install )
18
18
* [ Use] ( #use )
19
19
* [ API] ( #api )
20
- * [ ` toc(node[, options]) ` ] ( #tocnode-options )
20
+ * [ ` toc(tree[, options]) ` ] ( #toctree-options )
21
+ * [ ` Options ` ] ( #options )
22
+ * [ ` Result ` ] ( #result )
21
23
* [ Types] ( #types )
22
24
* [ Compatibility] ( #compatibility )
23
25
* [ Security] ( #security )
@@ -40,7 +42,7 @@ This package is wrapped in [`remark-toc`][remark-toc] for ease of use with
40
42
## Install
41
43
42
44
This 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] [ ] :
44
46
45
47
``` sh
46
48
npm install mdast-util-toc
@@ -105,12 +107,12 @@ Yields:
105
107
106
108
## API
107
109
108
- This package exports the identifier ` toc ` .
110
+ This package exports the identifier [ ` toc ` ] [ api-toc ] .
109
111
There is no default export.
110
112
111
- ### ` toc(node [, options]) `
113
+ ### ` toc(tree [, options]) `
112
114
113
- Generate a table of contents from [ ` node ` ] [ node ] .
115
+ Generate a table of contents from ` tree ` .
114
116
115
117
Looks for the first heading matching ` options.heading ` (case insensitive) and
116
118
returns 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
120
122
121
123
Links in the list to headings are based on GitHub’s style.
122
124
Only 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,
186
178
` -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
193
185
194
186
## Types
195
187
196
188
This 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 ] .
198
190
199
191
## Compatibility
200
192
201
193
Projects maintained by the unified collective are compatible with all maintained
202
194
versions 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+.
204
196
Our projects sometimes work with older versions, but this is not guaranteed.
205
197
206
198
## Security
@@ -313,14 +305,20 @@ abide by its terms.
313
305
314
306
[ is ] : https://github.com/syntax-tree/unist-util-is
315
307
316
- [ heading ] : https://github.com/syntax-tree/mdast#heading
308
+ [ list ] : https://github.com/syntax-tree/mdast#list
317
309
318
310
[ node ] : https://github.com/syntax-tree/mdast#node
319
311
320
- [ parents ] : #optionsparents
321
-
322
312
[ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
323
313
324
314
[ remark ] : https://github.com/remarkjs/remark
325
315
326
316
[ 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