Skip to content

Commit 5d64d0e

Browse files
authored
Merge pull request #2953 from ehuss/fix-heading-nav-level
Fix heading nav level
2 parents 7e7a3b4 + 718ceec commit 5d64d0e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

crates/mdbook-html/front-end/templates/toc.js.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ window.customElements.define('mdbook-sidebar-scrollbox', MDBookSidebarScrollbox)
392392
stack.push({level: nextLevel, ol: ol});
393393
}
394394
} else if (level < currentLevel) {
395-
while (stack.length > 1 && stack[stack.length - 1].level >= level) {
395+
while (stack.length > 1 && stack[stack.length - 1].level > level) {
396396
stack.pop();
397397
}
398398
}

tests/gui/heading-nav-collapsed.goml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ assert-text: (".current-header", "Heading 1")
1010
assert-attribute: ("li:has(> span > a[href='#heading-12'])", {"class": "header-item"})
1111
assert-attribute: ("li:has(> span > a[href='#heading-21'])", {"class": "header-item"})
1212

13+
assert-property: ("div.on-this-page", {"innerHTML": '<ol class="section"><li class="header-item expanded"><span class="chapter-link-wrapper"><a href="#heading-1" class="header-in-summary current-header">Heading 1</a></span><ol class="section"><li class="header-item expanded"><span class="chapter-link-wrapper"><a href="#heading-11" class="header-in-summary">Heading 1.1</a></span></li><li class="header-item"><span class="chapter-link-wrapper"><a href="#heading-12" class="header-in-summary">Heading 1.2</a><a class="chapter-fold-toggle header-toggle"><div>❱</div></a></span><ol class="section"><li class="header-item expanded"><span class="chapter-link-wrapper"><a href="#heading-121" class="header-in-summary">Heading 1.2.1</a></span></li><li class="header-item expanded"><span class="chapter-link-wrapper"><a href="#heading-122" class="header-in-summary">Heading 1.2.2</a></span></li></ol></li><li class="header-item expanded"><span class="chapter-link-wrapper"><a href="#heading-13" class="header-in-summary">Heading 1.3</a></span></li></ol></li><li class="header-item expanded"><span class="chapter-link-wrapper"><a href="#heading-2" class="header-in-summary">Heading 2</a></span><ol class="section"><li class="header-item"><span class="chapter-link-wrapper"><a href="#heading-21" class="header-in-summary">Heading 2.1</a><a class="chapter-fold-toggle header-toggle"><div>❱</div></a></span><ol class="section"><li class="header-item"><span class="chapter-link-wrapper"><a href="#heading-211" class="header-in-summary">Heading 2.1.1</a><a class="chapter-fold-toggle header-toggle"><div>❱</div></a></span><ol class="section"><li class="header-item"><span class="chapter-link-wrapper"><a href="#heading-2111" class="header-in-summary">Heading 2.1.1.1</a><a class="chapter-fold-toggle header-toggle"><div>❱</div></a></span><ol class="section"><li class="header-item expanded"><span class="chapter-link-wrapper"><a href="#heading-21111" class="header-in-summary">Heading 2.1.1.1.1</a></span></li></ol></li></ol></li></ol></li></ol></li></ol>'})
14+
1315
// Click 1.2, expands it.
1416
click: "a.header-in-summary[href='#heading-12']"
1517
assert-attribute: ("li:has(> span > a[href='#heading-12'])", {"class": "header-item expanded"})

0 commit comments

Comments
 (0)