Skip to content

Commit 623c332

Browse files
authored
Add minDepth
Closes GH-74. Closes GH-75. Reviewed-by: Titus Wormer <[email protected]>
1 parent 6d5c0ce commit 623c332

File tree

11 files changed

+348
-0
lines changed

11 files changed

+348
-0
lines changed

lib/search.js

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
*
1919
* This is inclusive: when set to `3`, level three headings are included
2020
* (those with three hashes, `###`).
21+
* @property {Rank | null | undefined} [minDepth=1]
22+
* Minimum heading depth to include in the table of contents (default: `1`).
23+
*
24+
* This is inclusive: when set to `3`, level three headings are included
25+
* (those with three hashes, `###`).
2126
* @property {string | null | undefined} [skip]
2227
* Headings to skip, wrapped in `new RegExp('^(' + value + ')$', 'i')`
2328
* (default: `undefined`).
@@ -125,6 +130,7 @@ export function search(root, expression, settings) {
125130
// A heading after the closing (if we were looking for one).
126131
if (
127132
(endIndex || !expression) &&
133+
(!settings.minDepth || node.depth >= settings.minDepth) &&
128134
(!settings.maxDepth || node.depth <= settings.maxDepth) &&
129135
(!skip || !skip.test(value))
130136
) {

readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ Configuration (TypeScript type).
140140
— maximum heading depth to include in the table of contents.
141141
This is inclusive: when set to `3`, level three headings are included
142142
(those with three hashes, `###`)
143+
* `minDepth` (`number`, default: `1`)
144+
— minimum heading depth to include in the table of contents.
145+
This is inclusive: when set to `3`, level three headings are included
146+
(those with three hashes, `###`)
143147
* `skip` (`string`, optional)
144148
— headings to skip, wrapped in `new RegExp('^(' + value + ')$', 'i')`.
145149
Any heading matching this expression will not be present in the table of
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"minDepth": 1
3+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Alpha
2+
3+
## Bravo
4+
5+
### Charlie
6+
7+
#### Delta
8+
9+
##### Echo
10+
11+
###### Foxtrot
+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
{
2+
"map": {
3+
"type": "list",
4+
"ordered": false,
5+
"spread": true,
6+
"children": [
7+
{
8+
"type": "listItem",
9+
"spread": true,
10+
"children": [
11+
{
12+
"type": "paragraph",
13+
"children": [
14+
{
15+
"type": "link",
16+
"title": null,
17+
"url": "#alpha",
18+
"children": [
19+
{
20+
"type": "text",
21+
"value": "Alpha"
22+
}
23+
]
24+
}
25+
]
26+
},
27+
{
28+
"type": "list",
29+
"ordered": false,
30+
"spread": true,
31+
"children": [
32+
{
33+
"type": "listItem",
34+
"spread": true,
35+
"children": [
36+
{
37+
"type": "paragraph",
38+
"children": [
39+
{
40+
"type": "link",
41+
"title": null,
42+
"url": "#bravo",
43+
"children": [
44+
{
45+
"type": "text",
46+
"value": "Bravo"
47+
}
48+
]
49+
}
50+
]
51+
},
52+
{
53+
"type": "list",
54+
"ordered": false,
55+
"spread": true,
56+
"children": [
57+
{
58+
"type": "listItem",
59+
"spread": true,
60+
"children": [
61+
{
62+
"type": "paragraph",
63+
"children": [
64+
{
65+
"type": "link",
66+
"title": null,
67+
"url": "#charlie",
68+
"children": [
69+
{
70+
"type": "text",
71+
"value": "Charlie"
72+
}
73+
]
74+
}
75+
]
76+
},
77+
{
78+
"type": "list",
79+
"ordered": false,
80+
"spread": true,
81+
"children": [
82+
{
83+
"type": "listItem",
84+
"spread": true,
85+
"children": [
86+
{
87+
"type": "paragraph",
88+
"children": [
89+
{
90+
"type": "link",
91+
"title": null,
92+
"url": "#delta",
93+
"children": [
94+
{
95+
"type": "text",
96+
"value": "Delta"
97+
}
98+
]
99+
}
100+
]
101+
},
102+
{
103+
"type": "list",
104+
"ordered": false,
105+
"spread": true,
106+
"children": [
107+
{
108+
"type": "listItem",
109+
"spread": true,
110+
"children": [
111+
{
112+
"type": "paragraph",
113+
"children": [
114+
{
115+
"type": "link",
116+
"title": null,
117+
"url": "#echo",
118+
"children": [
119+
{
120+
"type": "text",
121+
"value": "Echo"
122+
}
123+
]
124+
}
125+
]
126+
},
127+
{
128+
"type": "list",
129+
"ordered": false,
130+
"spread": false,
131+
"children": [
132+
{
133+
"type": "listItem",
134+
"spread": false,
135+
"children": [
136+
{
137+
"type": "paragraph",
138+
"children": [
139+
{
140+
"type": "link",
141+
"title": null,
142+
"url": "#foxtrot",
143+
"children": [
144+
{
145+
"type": "text",
146+
"value": "Foxtrot"
147+
}
148+
]
149+
}
150+
]
151+
}
152+
]
153+
}
154+
]
155+
}
156+
]
157+
}
158+
]
159+
}
160+
]
161+
}
162+
]
163+
}
164+
]
165+
}
166+
]
167+
}
168+
]
169+
}
170+
]
171+
}
172+
]
173+
}
174+
]
175+
}
176+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"minDepth": 4
3+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Alpha
2+
3+
## Bravo
4+
5+
### Charlie
6+
7+
#### Delta
8+
9+
##### Echo
10+
11+
###### Foxtrot
+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"map": {
3+
"type": "list",
4+
"ordered": false,
5+
"spread": true,
6+
"children": [
7+
{
8+
"type": "listItem",
9+
"spread": true,
10+
"children": [
11+
{
12+
"type": "paragraph",
13+
"children": [
14+
{
15+
"type": "link",
16+
"title": null,
17+
"url": "#delta",
18+
"children": [
19+
{
20+
"type": "text",
21+
"value": "Delta"
22+
}
23+
]
24+
}
25+
]
26+
},
27+
{
28+
"type": "list",
29+
"ordered": false,
30+
"spread": true,
31+
"children": [
32+
{
33+
"type": "listItem",
34+
"spread": true,
35+
"children": [
36+
{
37+
"type": "paragraph",
38+
"children": [
39+
{
40+
"type": "link",
41+
"title": null,
42+
"url": "#echo",
43+
"children": [
44+
{
45+
"type": "text",
46+
"value": "Echo"
47+
}
48+
]
49+
}
50+
]
51+
},
52+
{
53+
"type": "list",
54+
"ordered": false,
55+
"spread": false,
56+
"children": [
57+
{
58+
"type": "listItem",
59+
"spread": false,
60+
"children": [
61+
{
62+
"type": "paragraph",
63+
"children": [
64+
{
65+
"type": "link",
66+
"title": null,
67+
"url": "#foxtrot",
68+
"children": [
69+
{
70+
"type": "text",
71+
"value": "Foxtrot"
72+
}
73+
]
74+
}
75+
]
76+
}
77+
]
78+
}
79+
]
80+
}
81+
]
82+
}
83+
]
84+
}
85+
]
86+
}
87+
]
88+
}
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"minDepth": 6
3+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Alpha
2+
3+
## Bravo
4+
5+
### Charlie
6+
7+
#### Delta
8+
9+
##### Echo
10+
11+
###### Foxtrot
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"map": {
3+
"type": "list",
4+
"ordered": false,
5+
"spread": false,
6+
"children": [
7+
{
8+
"type": "listItem",
9+
"spread": false,
10+
"children": [
11+
{
12+
"type": "paragraph",
13+
"children": [
14+
{
15+
"type": "link",
16+
"title": null,
17+
"url": "#foxtrot",
18+
"children": [
19+
{
20+
"type": "text",
21+
"value": "Foxtrot"
22+
}
23+
]
24+
}
25+
]
26+
}
27+
]
28+
}
29+
]
30+
}
31+
}

0 commit comments

Comments
 (0)