From 455d6383f6e8aee0c3875476a08cab7eb387f836 Mon Sep 17 00:00:00 2001 From: David McArthur Date: Fri, 31 May 2024 13:20:16 +0100 Subject: [PATCH 1/4] failing tests --- test/fixtures/minimum-depth-1/config.json | 3 + test/fixtures/minimum-depth-1/input.md | 11 ++ test/fixtures/minimum-depth-1/output.json | 176 ++++++++++++++++++++++ test/fixtures/minimum-depth-4/config.json | 3 + test/fixtures/minimum-depth-4/input.md | 11 ++ test/fixtures/minimum-depth-4/output.json | 89 +++++++++++ test/fixtures/minimum-depth-6/config.json | 3 + test/fixtures/minimum-depth-6/input.md | 11 ++ test/fixtures/minimum-depth-6/output.json | 31 ++++ 9 files changed, 338 insertions(+) create mode 100644 test/fixtures/minimum-depth-1/config.json create mode 100644 test/fixtures/minimum-depth-1/input.md create mode 100644 test/fixtures/minimum-depth-1/output.json create mode 100644 test/fixtures/minimum-depth-4/config.json create mode 100644 test/fixtures/minimum-depth-4/input.md create mode 100644 test/fixtures/minimum-depth-4/output.json create mode 100644 test/fixtures/minimum-depth-6/config.json create mode 100644 test/fixtures/minimum-depth-6/input.md create mode 100644 test/fixtures/minimum-depth-6/output.json diff --git a/test/fixtures/minimum-depth-1/config.json b/test/fixtures/minimum-depth-1/config.json new file mode 100644 index 0000000..fbdc162 --- /dev/null +++ b/test/fixtures/minimum-depth-1/config.json @@ -0,0 +1,3 @@ +{ + "minDepth": 1 +} diff --git a/test/fixtures/minimum-depth-1/input.md b/test/fixtures/minimum-depth-1/input.md new file mode 100644 index 0000000..8c0c38a --- /dev/null +++ b/test/fixtures/minimum-depth-1/input.md @@ -0,0 +1,11 @@ +# Alpha + +## Bravo + +### Charlie + +#### Delta + +##### Echo + +###### Foxtrot diff --git a/test/fixtures/minimum-depth-1/output.json b/test/fixtures/minimum-depth-1/output.json new file mode 100644 index 0000000..edfaebd --- /dev/null +++ b/test/fixtures/minimum-depth-1/output.json @@ -0,0 +1,176 @@ +{ + "map": { + "type": "list", + "ordered": false, + "spread": true, + "children": [ + { + "type": "listItem", + "spread": true, + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "link", + "title": null, + "url": "#alpha", + "children": [ + { + "type": "text", + "value": "Alpha" + } + ] + } + ] + }, + { + "type": "list", + "ordered": false, + "spread": true, + "children": [ + { + "type": "listItem", + "spread": true, + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "link", + "title": null, + "url": "#bravo", + "children": [ + { + "type": "text", + "value": "Bravo" + } + ] + } + ] + }, + { + "type": "list", + "ordered": false, + "spread": true, + "children": [ + { + "type": "listItem", + "spread": true, + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "link", + "title": null, + "url": "#charlie", + "children": [ + { + "type": "text", + "value": "Charlie" + } + ] + } + ] + }, + { + "type": "list", + "ordered": false, + "spread": true, + "children": [ + { + "type": "listItem", + "spread": true, + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "link", + "title": null, + "url": "#delta", + "children": [ + { + "type": "text", + "value": "Delta" + } + ] + } + ] + }, + { + "type": "list", + "ordered": false, + "spread": true, + "children": [ + { + "type": "listItem", + "spread": true, + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "link", + "title": null, + "url": "#echo", + "children": [ + { + "type": "text", + "value": "Echo" + } + ] + } + ] + }, + { + "type": "list", + "ordered": false, + "spread": false, + "children": [ + { + "type": "listItem", + "spread": false, + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "link", + "title": null, + "url": "#foxtrot", + "children": [ + { + "type": "text", + "value": "Foxtrot" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } +} diff --git a/test/fixtures/minimum-depth-4/config.json b/test/fixtures/minimum-depth-4/config.json new file mode 100644 index 0000000..f61182d --- /dev/null +++ b/test/fixtures/minimum-depth-4/config.json @@ -0,0 +1,3 @@ +{ + "minDepth": 4 +} diff --git a/test/fixtures/minimum-depth-4/input.md b/test/fixtures/minimum-depth-4/input.md new file mode 100644 index 0000000..8c0c38a --- /dev/null +++ b/test/fixtures/minimum-depth-4/input.md @@ -0,0 +1,11 @@ +# Alpha + +## Bravo + +### Charlie + +#### Delta + +##### Echo + +###### Foxtrot diff --git a/test/fixtures/minimum-depth-4/output.json b/test/fixtures/minimum-depth-4/output.json new file mode 100644 index 0000000..7817dd0 --- /dev/null +++ b/test/fixtures/minimum-depth-4/output.json @@ -0,0 +1,89 @@ +{ + "map": { + "type": "list", + "ordered": false, + "spread": true, + "children": [ + { + "type": "listItem", + "spread": true, + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "link", + "title": null, + "url": "#delta", + "children": [ + { + "type": "text", + "value": "Delta" + } + ] + } + ] + }, + { + "type": "list", + "ordered": false, + "spread": true, + "children": [ + { + "type": "listItem", + "spread": true, + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "link", + "title": null, + "url": "#echo", + "children": [ + { + "type": "text", + "value": "Echo" + } + ] + } + ] + }, + { + "type": "list", + "ordered": false, + "spread": false, + "children": [ + { + "type": "listItem", + "spread": false, + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "link", + "title": null, + "url": "#foxtrot", + "children": [ + { + "type": "text", + "value": "Foxtrot" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } +} diff --git a/test/fixtures/minimum-depth-6/config.json b/test/fixtures/minimum-depth-6/config.json new file mode 100644 index 0000000..f79c7fa --- /dev/null +++ b/test/fixtures/minimum-depth-6/config.json @@ -0,0 +1,3 @@ +{ + "minDepth": 6 +} diff --git a/test/fixtures/minimum-depth-6/input.md b/test/fixtures/minimum-depth-6/input.md new file mode 100644 index 0000000..8c0c38a --- /dev/null +++ b/test/fixtures/minimum-depth-6/input.md @@ -0,0 +1,11 @@ +# Alpha + +## Bravo + +### Charlie + +#### Delta + +##### Echo + +###### Foxtrot diff --git a/test/fixtures/minimum-depth-6/output.json b/test/fixtures/minimum-depth-6/output.json new file mode 100644 index 0000000..562f984 --- /dev/null +++ b/test/fixtures/minimum-depth-6/output.json @@ -0,0 +1,31 @@ +{ + "map": { + "type": "list", + "ordered": false, + "spread": false, + "children": [ + { + "type": "listItem", + "spread": false, + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "link", + "title": null, + "url": "#foxtrot", + "children": [ + { + "type": "text", + "value": "Foxtrot" + } + ] + } + ] + } + ] + } + ] + } +} From 6cf2256b29063a8a69d2250546a5102b3f0b1339 Mon Sep 17 00:00:00 2001 From: David McArthur Date: Fri, 31 May 2024 13:21:48 +0100 Subject: [PATCH 2/4] add minDepth option --- lib/search.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/search.js b/lib/search.js index 2f07218..10f4ee1 100644 --- a/lib/search.js +++ b/lib/search.js @@ -18,6 +18,11 @@ * * This is inclusive: when set to `3`, level three headings are included * (those with three hashes, `###`). + * @property {Rank | null | undefined} [minDepth=6] + * Minimum heading depth to include in the table of contents (default: `1`). + * + * This is inclusive: when set to `3`, level three headings are included + * (those with three hashes, `###`). * @property {string | null | undefined} [skip] * Headings to skip, wrapped in `new RegExp('^(' + value + ')$', 'i')` * (default: `undefined`). @@ -125,6 +130,7 @@ export function search(root, expression, settings) { // A heading after the closing (if we were looking for one). if ( (endIndex || !expression) && + (!settings.minDepth || node.depth >= settings.minDepth) && (!settings.maxDepth || node.depth <= settings.maxDepth) && (!skip || !skip.test(value)) ) { From 76f8cad096b8098ca59e5411673400c73033b40b Mon Sep 17 00:00:00 2001 From: David McArthur Date: Fri, 31 May 2024 13:31:14 +0100 Subject: [PATCH 3/4] add minDepth to readme --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index a181642..3d6ec12 100644 --- a/readme.md +++ b/readme.md @@ -140,6 +140,10 @@ Configuration (TypeScript type). — maximum heading depth to include in the table of contents. This is inclusive: when set to `3`, level three headings are included (those with three hashes, `###`) +* `minDepth` (`number`, default: `1`) + — minimum heading depth to include in the table of contents. + This is inclusive: when set to `3`, level three headings are included + (those with three hashes, `###`) * `skip` (`string`, optional) — headings to skip, wrapped in `new RegExp('^(' + value + ')$', 'i')`. Any heading matching this expression will not be present in the table of From bbb8de439f69558f9e5f3c60cb8fa3a1140262d6 Mon Sep 17 00:00:00 2001 From: David McArthur Date: Fri, 31 May 2024 15:32:45 +0100 Subject: [PATCH 4/4] fix jsdoc --- lib/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/search.js b/lib/search.js index 10f4ee1..604ec69 100644 --- a/lib/search.js +++ b/lib/search.js @@ -18,7 +18,7 @@ * * This is inclusive: when set to `3`, level three headings are included * (those with three hashes, `###`). - * @property {Rank | null | undefined} [minDepth=6] + * @property {Rank | null | undefined} [minDepth=1] * Minimum heading depth to include in the table of contents (default: `1`). * * This is inclusive: when set to `3`, level three headings are included