Skip to content

Commit 6eaa7db

Browse files
committed
feat: set default markdownTOC depth to 2
1 parent 38cbb3c commit 6eaa7db

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,10 @@ Generate a table of contents from the current markdown file, based on markdown h
279279
280280
##### Params
281281
282-
|name |description |
283-
|--------|------------------------------------------------------------------------------------------------------------------|
284-
|minDepth|exclude headers with lower "depth". e.g. if set to 2, `# H1` would be excluded but `## H2` would be included. |
285-
|maxDepth|exclude headers with higher "depth". e.g. if set to 3, `#### H4` would be excluded but `### H3` would be included.|
282+
|name |description |
283+
|--------|------------------------------------------------------------------------------------------------------------------------|
284+
|minDepth|exclude headers with lower "depth". e.g. if set to 2, `# H1` would be excluded but `## H2` would be included. @default 2|
285+
|maxDepth|exclude headers with higher "depth". e.g. if set to 3, `#### H4` would be excluded but `### H3` would be included.p |
286286
<!-- codegen:end -->
287287
288288
##### Demo

src/presets/markdown-toc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import * as os from 'os'
1010
*
1111
* `<!-- codegen:start {preset: markdownTOC, minDepth: 2, maxDepth: 5} -->`
1212
*
13-
* @param minDepth exclude headers with lower "depth". e.g. if set to 2, `# H1` would be excluded but `## H2` would be included.
14-
* @param maxDepth exclude headers with higher "depth". e.g. if set to 3, `#### H4` would be excluded but `### H3` would be included.
13+
* @param minDepth exclude headers with lower "depth". e.g. if set to 2, `# H1` would be excluded but `## H2` would be included. @default 2
14+
* @param maxDepth exclude headers with higher "depth". e.g. if set to 3, `#### H4` would be excluded but `### H3` would be included.p
1515
*/
1616
export const markdownTOC: Preset<{minDepth?: number; maxDepth?: number}> = ({meta, options}) => {
1717
const lines = fs
@@ -21,7 +21,7 @@ export const markdownTOC: Preset<{minDepth?: number; maxDepth?: number}> = ({met
2121
.map(line => line.trim())
2222
const headings = lines
2323
.filter(line => /^#+ /.exec(line))
24-
.filter(line => line.startsWith('#'.repeat(options.minDepth || 1)))
24+
.filter(line => line.startsWith('#'.repeat(options.minDepth || 2)))
2525
.filter(line => line.split(' ')[0].length < (options.maxDepth || Number.POSITIVE_INFINITY))
2626
const minHashes = lodash.min(headings.map(h => h.split(' ')[0].length))!
2727
return headings

test/presets/markdown-toc.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,14 @@ test('generate markdown', () => {
6060
options: {},
6161
}),
6262
).toMatchInlineSnapshot(`
63-
"- [H1](#h1)
64-
- [H2](#h2)
65-
- [H3](#h3)
66-
- [Another H3](#another-h3)
67-
- [H4 duplicate](#h4-duplicate)
68-
- [H5](#h5)
69-
- [H5](#h5-1)
70-
- [H4 duplicate](#h4-duplicate-1)
71-
- [Another H2](#another-h2)"
63+
"- [H2](#h2)
64+
- [H3](#h3)
65+
- [Another H3](#another-h3)
66+
- [H4 duplicate](#h4-duplicate)
67+
- [H5](#h5)
68+
- [H5](#h5-1)
69+
- [H4 duplicate](#h4-duplicate-1)
70+
- [Another H2](#another-h2)"
7271
`)
7372

7473
expect(

0 commit comments

Comments
 (0)