diff --git a/crates/mdbook-html/src/html/hide_lines.rs b/crates/mdbook-html/src/html/hide_lines.rs index c81b44d8..8dbe7b12 100644 --- a/crates/mdbook-html/src/html/hide_lines.rs +++ b/crates/mdbook-html/src/html/hide_lines.rs @@ -141,7 +141,14 @@ fn partition_rust_source(s: &str) -> (&str, &str) { let split_idx = match HEADER_RE.captures(s) { Some(caps) => { let attributes = &caps[1]; - attributes.len() + if attributes.trim().is_empty() { + // Don't include pure whitespace as an attribute. The + // whitespace in the regex is intended to handle multiple + // attributes *separated* by potential whitespace. + 0 + } else { + attributes.len() + } } None => 0, }; @@ -181,6 +188,6 @@ fn it_partitions_rust_source() { ); assert_eq!( partition_rust_source(" // Example"), - (" ", "// Example") + ("", " // Example") ); } diff --git a/tests/testsuite/rendering/code_blocks_fenced_with_indent/expected/code-blocks-fenced-with-indent.html b/tests/testsuite/rendering/code_blocks_fenced_with_indent/expected/code-blocks-fenced-with-indent.html index e2bdfd2b..b4ed1ef4 100644 --- a/tests/testsuite/rendering/code_blocks_fenced_with_indent/expected/code-blocks-fenced-with-indent.html +++ b/tests/testsuite/rendering/code_blocks_fenced_with_indent/expected/code-blocks-fenced-with-indent.html @@ -1,6 +1,6 @@
#![allow(unused)]
- fn main() {
-// This has a first line that is indented.
+fn main() {
+ // This has a first line that is indented.
println!("hello");
}
\ No newline at end of file