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:
parent
3992bc18f5
commit
ddf02e0c0c
2 changed files with 11 additions and 4 deletions
|
|
@ -141,7 +141,14 @@ fn partition_rust_source(s: &str) -> (&str, &str) {
|
||||||
let split_idx = match HEADER_RE.captures(s) {
|
let split_idx = match HEADER_RE.captures(s) {
|
||||||
Some(caps) => {
|
Some(caps) => {
|
||||||
let attributes = &caps[1];
|
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,
|
None => 0,
|
||||||
};
|
};
|
||||||
|
|
@ -181,6 +188,6 @@ fn it_partitions_rust_source() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
partition_rust_source(" // Example"),
|
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>
|
<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)]
|
<pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
|
||||||
</span><span class="boring"> fn main() {
|
</span><span class="boring">fn main() {
|
||||||
</span>// This has a first line that is indented.
|
</span> // This has a first line that is indented.
|
||||||
println!("hello");
|
println!("hello");
|
||||||
<span class="boring">}</span></code></pre>
|
<span class="boring">}</span></code></pre>
|
||||||
Loading…
Add table
Reference in a new issue