diff --git a/src/block.rs b/src/block.rs index ba8410c..fe0ef61 100644 --- a/src/block.rs +++ b/src/block.rs @@ -353,7 +353,7 @@ impl<'s> TreeParser<'s> { span_end: Range, mut lines: &mut [Range], ) { - 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() { diff --git a/src/lib.rs b/src/lib.rs index 6a3fbb6..5a94bdc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1534,7 +1534,39 @@ mod test { test_parse!( "``` =html\n\n```", Start(RawBlock { format: "html" }, Attributes::new()), - Str("
\n".into()), + Str("
".into()), + End(RawBlock { format: "html" }), + ); + } + + #[test] + fn raw_block_whitespace() { + test_parse!( + concat!( + "```=html\n", // + "\n", // + "\n", // + "```\n", // + "\n", // + "paragraph\n", // + "\n", // + "```=html\n", // + "\n", // + "\n", // + "```\n", // + ), + Start(RawBlock { format: "html" }, Attributes::new()), + Str("\n".into()), + Str("".into()), + End(RawBlock { format: "html" }), + Blankline, + Start(Paragraph, Attributes::new()), + Str("paragraph".into()), + End(Paragraph), + Blankline, + Start(RawBlock { format: "html" }, Attributes::new()), + Str("\n".into()), + Str("".into()), End(RawBlock { format: "html" }), ); } diff --git a/tests/html-ut/ut/raw_blocks.test b/tests/html-ut/ut/raw_blocks.test new file mode 100644 index 0000000..0c6d97f --- /dev/null +++ b/tests/html-ut/ut/raw_blocks.test @@ -0,0 +1,19 @@ +```` +```=html + + +``` + +paragraph + +```=html + + +``` +. + + +

paragraph

+
+
+````