mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Fix code block whitespace handling
This commit is contained in:
@@ -220,7 +220,7 @@ fn parse_codeblock(buf: &[u8]) -> Parsed<'_> {
|
||||
let mut found = None;
|
||||
for idx in (0..working.len()).filter(|idx| working[*idx..].starts_with(&end_pat)) {
|
||||
let (eol_txt, rest) = parse_to_newline(&working[(idx + end_pat.len())..]);
|
||||
if !eol_txt.iter().any(u8::is_ascii_whitespace) {
|
||||
if eol_txt.iter().all(u8::is_ascii_whitespace) {
|
||||
found = Some((&working[..idx], rest));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -364,3 +364,16 @@ fn test_snake_case() {
|
||||
let res = entrypoint(SNAKE_CASE);
|
||||
assert_eq!(res, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_codeblock_trailing_whitespace() {
|
||||
let buf = "```rust\ncode\n``` \nrest";
|
||||
let (t, r) = parse_codeblock(buf.as_bytes());
|
||||
assert_eq!(t, MdTree::CodeBlock { txt: "code", lang: Some("rust") });
|
||||
assert_eq!(r, b"\nrest");
|
||||
|
||||
let buf = "```rust\ncode\n```abc\nrest";
|
||||
let (t, r) = parse_codeblock(buf.as_bytes());
|
||||
assert_eq!(t, MdTree::CodeBlock { txt: "code\n```abc\nrest", lang: Some("rust") });
|
||||
assert_eq!(r, b"");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user