Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion crates/mdbook-html/src/html/hide_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -179,4 +186,8 @@ fn it_partitions_rust_source() {
),
("\n#![allow(foo)]\n\n#![allow(bar)]\n\n", "let x = 1;")
);
assert_eq!(
partition_rust_source(" // Example"),
("", " // Example")
);
}
6 changes: 6 additions & 0 deletions tests/testsuite/rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,9 @@ Html text was:
fn html_blocks() {
BookTest::from_dir("rendering/html_blocks").check_all_main_files();
}

// Test for a fenced code block that is also indented.
#[test]
fn code_block_fenced_with_indent() {
BookTest::from_dir("rendering/code_blocks_fenced_with_indent").check_all_main_files();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[book]
title = "code_blocks_fenced_with_indent"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1 id="code-blocks-fenced-with-indent"><a class="header" href="#code-blocks-fenced-with-indent">Code blocks fenced with indent</a></h1>
<pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> // This has a first line that is indented.
println!("hello");
<span class="boring">}</span></code></pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Summary

- [Code blocks fenced with indent](./code-blocks-fenced-with-indent.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code blocks fenced with indent

```rust
// This has a first line that is indented.
println!("hello");
```