block: rm extra new line after raw blocks

match reference implementation
This commit is contained in:
Noah Hellman 2023-07-14 20:34:46 +02:00
parent b60650dd0d
commit 0586bf6a44
3 changed files with 61 additions and 2 deletions

View file

@ -353,7 +353,7 @@ impl<'s> TreeParser<'s> {
span_end: Range<usize>,
mut lines: &mut [Range<usize>],
) {
if let Kind::Fenced { indent, .. } = k {
if let Kind::Fenced { indent, spec, .. } = k {
for line in lines.iter_mut() {
let indent_line = self.src.as_bytes()[line.clone()]
.iter()
@ -361,6 +361,14 @@ impl<'s> TreeParser<'s> {
.count();
line.start += (*indent).min(indent_line);
}
// trim ending whitespace of raw block
if spec.starts_with('=') {
let l = lines.len();
if l > 0 {
lines[l - 1] = self.trim_end(lines[l - 1].clone());
}
}
} else {
// trim starting whitespace of each inline
for line in lines.iter_mut() {

View file

@ -1534,7 +1534,39 @@ mod test {
test_parse!(
"``` =html\n<table>\n```",
Start(RawBlock { format: "html" }, Attributes::new()),
Str("<table>\n".into()),
Str("<table>".into()),
End(RawBlock { format: "html" }),
);
}
#[test]
fn raw_block_whitespace() {
test_parse!(
concat!(
"```=html\n", //
"<tag1>\n", //
"<tag2>\n", //
"```\n", //
"\n", //
"paragraph\n", //
"\n", //
"```=html\n", //
"</tag2>\n", //
"</tag1>\n", //
"```\n", //
),
Start(RawBlock { format: "html" }, Attributes::new()),
Str("<tag1>\n".into()),
Str("<tag2>".into()),
End(RawBlock { format: "html" }),
Blankline,
Start(Paragraph, Attributes::new()),
Str("paragraph".into()),
End(Paragraph),
Blankline,
Start(RawBlock { format: "html" }, Attributes::new()),
Str("</tag2>\n".into()),
Str("</tag1>".into()),
End(RawBlock { format: "html" }),
);
}

View file

@ -0,0 +1,19 @@
````
```=html
<tag1>
<tag2>
```
paragraph
```=html
</tag2>
</tag1>
```
.
<tag1>
<tag2>
<p>paragraph</p>
</tag2>
</tag1>
````