fixup! e15eb6a0955c5bc1f747738a03bd9fbe93f6ffb1

This commit is contained in:
Noah Hellman 2022-12-02 08:16:47 +01:00
parent 5fe724e873
commit 60372cda33

View file

@ -85,7 +85,7 @@ impl<'s> Parser<'s> {
let lines = &mut lines[blanklines..]; let lines = &mut lines[blanklines..];
Block::parse(lines.iter().map(|sp| sp.of(self.src))).map_or( Block::parse(lines.iter().map(|sp| sp.of(self.src))).map_or(
blanklines, blanklines,
|(kind, span, len)| { |(kind, span, line_count)| {
let start = lines.get(0).map(|sp| sp.start()).unwrap(); let start = lines.get(0).map(|sp| sp.start()).unwrap();
let span = span.translate(start); let span = span.translate(start);
match &kind { match &kind {
@ -99,8 +99,8 @@ impl<'s> Parser<'s> {
first.end(), first.end(),
); );
let len = match l { let len = match l {
CodeBlock { .. } => len - 2, CodeBlock { .. } => line_count - 2,
_ => len, _ => line_count,
}; };
if !matches!(l, Leaf::CodeBlock { .. }) { if !matches!(l, Leaf::CodeBlock { .. }) {
// trim ending whitespace of block // trim ending whitespace of block
@ -144,7 +144,7 @@ impl<'s> Parser<'s> {
} }
} }
self.tree.exit(); self.tree.exit();
blanklines + len blanklines + line_count
}, },
) )
} }
@ -159,9 +159,8 @@ impl Block {
kind, kind,
Self::Leaf(CodeBlock { .. }) | Self::Container(Div { .. }) Self::Leaf(CodeBlock { .. }) | Self::Container(Div { .. })
); );
let line_count = 1 let line_count_match = lines.take_while(|l| kind.continues(l)).count();
+ lines.take_while(|l| kind.continues(l)).count() let line_count = 1 + line_count_match + usize::from(has_end_delimiter);
+ usize::from(has_end_delimiter);
(kind, sp, line_count) (kind, sp, line_count)
}) })
} }
@ -417,7 +416,7 @@ mod test {
); );
test_parse!( test_parse!(
concat!( concat!(
"````lang\n", "```` lang\n",
"l0\n", "l0\n",
"```\n", "```\n",
" l1\n", " l1\n",