Files
mdBook/tests/testsuite/index.rs
Eric Huss 5282083dec Fix heading nav with folded chapters
This fixes an issue when folding is enabled. The folding was not
properly hiding the sub-chapters because it was assuming it could hide
the next list element. However, the heading nav was the next list
element, so the remaining chapters remained visible.

The solution required some deeper changes to how the chapters were
organized in the sidebar. Instead of nested chapters being a list
element *sibling*, the nested chapter's `ol` is now a *child* of its
parent chapter. This makes it much easier to just hide everything
without regard of the exact sibling order.

This required wrapping the chapter title and the toggle chevron inside a
span so that the flex layout could be localized to just those elements,
and allow the following `ol` elements to lay out regularly.

Closes https://github.com/rust-lang/mdBook/issues/2880
2025-10-20 17:31:40 -07:00

45 lines
1.2 KiB
Rust

//! Tests for the index preprocessor.
use crate::prelude::*;
// Checks basic README to index.html conversion.
#[test]
fn readme_to_index() {
let mut test = BookTest::from_dir("index/basic_readme");
test.check_main_file(
"book/index.html",
str![[r##"<h1 id="intro"><a class="header" href="#intro">Intro</a></h1>"##]],
)
.check_main_file(
"book/first/index.html",
str![[r##"<h1 id="first"><a class="header" href="#first">First</a></h1>"##]],
)
.check_main_file(
"book/second/index.html",
str![[r##"<h1 id="second"><a class="header" href="#second">Second</a></h1>"##]],
)
.check_toc_js(str![[r#"
<ol class="chapter">
<li class="chapter-item expanded ">
<span class="chapter-link-wrapper">
<a href="index.html">Intro</a>
</span>
</li>
<li class="chapter-item expanded ">
<span class="chapter-link-wrapper">
<a href="first/index.html">
<strong aria-hidden="true">1.</strong> First</a>
</span>
</li>
<li class="chapter-item expanded ">
<span class="chapter-link-wrapper">
<a href="second/index.html">
<strong aria-hidden="true">2.</strong> Second</a>
</span>
</li>
</ol>
"#]]);
assert!(test.dir.join("book/index.html").exists());
assert!(!test.dir.join("book/README.html").exists());
}