mirror of
https://github.com/rust-lang/mdBook.git
synced 2025-12-27 09:05:40 -05:00
Fix rust fenced code blocks with an indent
This fixes a bug in the Rust code block partitioning that was incorrectly removing the whitespace from the beginning of a code block.
This commit is contained in:
@@ -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")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +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.
|
||||
</span><span class="boring">fn main() {
|
||||
</span> // This has a first line that is indented.
|
||||
println!("hello");
|
||||
<span class="boring">}</span></code></pre>
|
||||
Reference in New Issue
Block a user