Skip to content

Commit

Permalink
Handle minLevel with inlineFirstLevel style
Browse files Browse the repository at this point in the history
  • Loading branch information
johansatge committed May 15, 2024
1 parent 4d62158 commit ea91117
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
23 changes: 23 additions & 0 deletions test/headings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit ea91117

Please sign in to comment.