From ea9111758e9177c393c9e2843aa72e8ddfa3466e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Satg=C3=A9?= Date: Thu, 16 May 2024 00:14:30 +0200 Subject: [PATCH] Handle minLevel with inlineFirstLevel style --- main.js | 5 ++++- test/headings.test.js | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index acb22bb..45766e3 100644 --- a/main.js +++ b/main.js @@ -152,8 +152,11 @@ function getMarkdownNestedListFromHeadings(headings, options) { } function getMarkdownInlineFirstLevelFromHeadings(headings, options) { + const minLevel = options.minLevel > 0 + ? options.minLevel + : Math.min(...headings.map((heading) => heading.level)) const items = headings - .filter((heading) => heading.level === 1) + .filter((heading) => heading.level === minLevel) .map((heading) => { return getMarkdownHeading(heading, options) }) diff --git a/test/headings.test.js b/test/headings.test.js index 84e9585..614ad8d 100644 --- a/test/headings.test.js +++ b/test/headings.test.js @@ -157,6 +157,29 @@ describe('Headings', () => { const md = getMarkdownFromHeadings(testStandardHeadings, options) const expectedMd = sanitizeMd(` Title 1 level 1 | Title 2 level 1 | Title 3 level 1 +`) + expect(md).toEqual(expectedMd) + }) + + test('Returns flat list with custom level', () => { + const options = parseOptionsFromSourceText('') + options.style = 'inlineFirstLevel' + options.includeLinks = false + options.minLevel = 3 + const md = getMarkdownFromHeadings(testStandardHeadings, options) + const expectedMd = sanitizeMd(` +Title 1 level 3 +`) + expect(md).toEqual(expectedMd) + }) + + test('Returns flat list with default level', () => { + const options = parseOptionsFromSourceText('') + options.style = 'inlineFirstLevel' + options.includeLinks = false + const md = getMarkdownFromHeadings(testHeadingsWithoutFirstLevel, options) + const expectedMd = sanitizeMd(` +Title 1 level 2 | Title 2 level 2 | Title 3 level 2 `) expect(md).toEqual(expectedMd) })