fixup! add block parser in addition to block tree parser

This commit is contained in:
Noah Hellman 2023-01-21 12:33:41 +01:00
parent 7a5ef1e695
commit 0f7ef85f6e

View file

@ -78,7 +78,7 @@ pub enum Container {
/// Span is `>`. /// Span is `>`.
Blockquote, Blockquote,
/// Span is class specifier. /// Span is class specifier, possibly empty.
Div, Div,
/// Span is the list marker. /// Span is the list marker.
@ -130,11 +130,9 @@ impl<'s> TreeParser<'s> {
BlockParser::parse(lines.iter().map(|sp| sp.of(self.src))).map_or( BlockParser::parse(lines.iter().map(|sp| sp.of(self.src))).map_or(
0, 0,
|(indent, kind, span, line_count)| { |(indent, kind, span, line_count)| {
let lines = { let truncated = line_count > lines.len();
let l = lines.len().min(line_count); let l = line_count.min(lines.len());
&mut lines[..l] let lines = &mut lines[..l];
};
let truncated = lines.len() < line_count;
let span = span.translate(lines[0].start()); let span = span.translate(lines[0].start());
// skip part of first inline that is shared with the block span // skip part of first inline that is shared with the block span
@ -376,6 +374,8 @@ impl BlockParser {
/// Determine if this line continues the block. /// Determine if this line continues the block.
fn continues(&mut self, line: &str) -> bool { fn continues(&mut self, line: &str) -> bool {
let line_t = line.trim();
let empty = line_t.is_empty();
match self.kind { match self.kind {
Block::Atom(..) => false, Block::Atom(..) => false,
Block::Leaf(Paragraph | Heading | Table) => !line.trim().is_empty(), Block::Leaf(Paragraph | Heading | Table) => !line.trim().is_empty(),
@ -383,7 +383,7 @@ impl BlockParser {
Block::Container(Blockquote) => line.trim().starts_with('>'), Block::Container(Blockquote) => line.trim().starts_with('>'),
Block::Container(Footnote | ListItem(..)) => { Block::Container(Footnote | ListItem(..)) => {
let spaces = line.chars().take_while(|c| c.is_whitespace()).count(); let spaces = line.chars().take_while(|c| c.is_whitespace()).count();
line.trim().is_empty() || spaces > self.indent empty || spaces > self.indent
} }
Block::Container(Div) | Block::Leaf(CodeBlock) => { Block::Container(Div) | Block::Leaf(CodeBlock) => {
let (fence, fence_length) = self.fence.unwrap(); let (fence, fence_length) = self.fence.unwrap();