fixup! 5a33d9cae978e1e151d571c610b0f6584db00cc8

This commit is contained in:
Noah Hellman 2022-11-30 19:56:08 +01:00
parent 3ca0002df8
commit d32519009e

View file

@ -98,29 +98,33 @@ impl<'s> Parser<'s> {
} }
Block::Container(c) => { Block::Container(c) => {
let (skip_chars, skip_lines_suffix) = match &c { let (skip_chars, skip_lines_suffix) = match &c {
Blockquote => (1, 0), Blockquote => (2, 0),
ListItem { indent } | Footnote { indent } => (*indent, 0), ListItem { indent } | Footnote { indent } => (*indent, 0),
Div { .. } => (0, 1), Div { .. } => (0, 1),
}; };
let line_count = lines.len() - skip_lines_suffix; let line_count_inner = lines.len() - skip_lines_suffix;
// update spans, remove indentation / container prefix // update spans, remove indentation / container prefix
lines[0] = lines[0].with_start(span.end()); lines[0] = lines[0].with_start(span.end());
lines.iter_mut().skip(1).take(line_count).for_each(|sp| { lines
let skip = (sp .iter_mut()
.of(self.src) .skip(1)
.chars() .take(line_count_inner)
.take_while(|c| c.is_whitespace()) .for_each(|sp| {
.count() let skip = (sp
+ usize::from(skip_chars)) .of(self.src)
.min(sp.len()); .chars()
*sp = sp.trim_start(skip); .take_while(|c| c.is_whitespace())
}); .count()
+ usize::from(skip_chars))
.min(sp.len());
*sp = sp.trim_start(skip);
});
self.tree.enter(kind, span); self.tree.enter(kind, span);
let mut l = 0; let mut l = 0;
while l < line_count { while l < line_count_inner {
l += self.parse_block(&mut lines[l..line_count]); l += self.parse_block(&mut lines[l..line_count_inner]);
} }
} }
} }
@ -165,12 +169,21 @@ impl Block {
}) })
}) })
.flatten(), .flatten(),
'>' => chars.next().map_or(true, |c| c == ' ').then(|| { '>' => {
( if let Some(c) = chars.next() {
Self::Container(Blockquote), c.is_whitespace().then(|| {
Span::by_len(start, line.len() - chars.as_str().len() - 1), (
) Self::Container(Blockquote),
}), Span::by_len(start, line.len() - chars.as_str().len() - 1),
)
})
} else {
Some((
Self::Container(Blockquote),
Span::by_len(start, line.len() - chars.as_str().len()),
))
}
}
f @ ('`' | ':') => { f @ ('`' | ':') => {
let fence_length = chars.take_while(|c| *c == f).count() + 1; let fence_length = chars.take_while(|c| *c == f).count() + 1;
(fence_length >= 3) (fence_length >= 3)