block: rm extra new line after raw blocks
match reference implementation
This commit is contained in:
parent
b60650dd0d
commit
0586bf6a44
3 changed files with 61 additions and 2 deletions
10
src/block.rs
10
src/block.rs
|
@ -353,7 +353,7 @@ impl<'s> TreeParser<'s> {
|
||||||
span_end: Range<usize>,
|
span_end: Range<usize>,
|
||||||
mut lines: &mut [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() {
|
for line in lines.iter_mut() {
|
||||||
let indent_line = self.src.as_bytes()[line.clone()]
|
let indent_line = self.src.as_bytes()[line.clone()]
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -361,6 +361,14 @@ impl<'s> TreeParser<'s> {
|
||||||
.count();
|
.count();
|
||||||
line.start += (*indent).min(indent_line);
|
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 {
|
} else {
|
||||||
// trim starting whitespace of each inline
|
// trim starting whitespace of each inline
|
||||||
for line in lines.iter_mut() {
|
for line in lines.iter_mut() {
|
||||||
|
|
34
src/lib.rs
34
src/lib.rs
|
@ -1534,7 +1534,39 @@ mod test {
|
||||||
test_parse!(
|
test_parse!(
|
||||||
"``` =html\n<table>\n```",
|
"``` =html\n<table>\n```",
|
||||||
Start(RawBlock { format: "html" }, Attributes::new()),
|
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" }),
|
End(RawBlock { format: "html" }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
19
tests/html-ut/ut/raw_blocks.test
Normal file
19
tests/html-ut/ut/raw_blocks.test
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
````
|
||||||
|
```=html
|
||||||
|
<tag1>
|
||||||
|
<tag2>
|
||||||
|
```
|
||||||
|
|
||||||
|
paragraph
|
||||||
|
|
||||||
|
```=html
|
||||||
|
</tag2>
|
||||||
|
</tag1>
|
||||||
|
```
|
||||||
|
.
|
||||||
|
<tag1>
|
||||||
|
<tag2>
|
||||||
|
<p>paragraph</p>
|
||||||
|
</tag2>
|
||||||
|
</tag1>
|
||||||
|
````
|
Loading…
Reference in a new issue