parse: merge enter / exit block events match branch

This commit is contained in:
Noah Hellman 2023-01-21 21:07:42 +01:00
parent 50632204a3
commit 6befcad52a

View file

@ -456,49 +456,42 @@ impl<'s> Parser<'s> {
continue; continue;
} }
}, },
tree::EventKind::Enter(c) | tree::EventKind::Exit(c) tree::EventKind::Enter(c) | tree::EventKind::Exit(c) => {
if matches!(c, block::Node::Leaf(block::Leaf::LinkDefinition)) => let enter = matches!(ev.kind, tree::EventKind::Enter(..));
{ let cont = match c {
block::Node::Leaf(l) => {
if matches!(l, block::Leaf::LinkDefinition) {
// ignore link definitions // ignore link definitions
self.tree.take_inlines().last(); self.tree.take_inlines().last();
continue; continue;
} }
tree::EventKind::Enter(c) => match c { if enter {
block::Node::Leaf(l) => {
self.inlines.set_spans(self.tree.take_inlines()); self.inlines.set_spans(self.tree.take_inlines());
self.inline_parser = Some(inline::Parser::new(self.inlines.chars())); self.inline_parser =
let container = Container::from_leaf_block(content, l); Some(inline::Parser::new(self.inlines.chars()));
Event::Start(container, attributes)
} }
block::Node::Container(c) => { Container::from_leaf_block(content, l)
let container = match c { }
block::Node::Container(c) => match c {
block::Container::Blockquote => Container::Blockquote, block::Container::Blockquote => Container::Blockquote,
block::Container::Div { .. } => Container::Div { block::Container::Div { .. } => Container::Div {
class: (!ev.span.is_empty()).then(|| content), class: (!ev.span.is_empty()).then(|| content),
}, },
block::Container::Footnote => { block::Container::Footnote => {
assert!(enter);
self.footnotes.insert(content, self.tree.take_branch()); self.footnotes.insert(content, self.tree.take_branch());
continue; continue;
} }
_ => panic!(), block::Container::List(ty) => todo!(),
block::Container::ListItem(ty) => todo!(),
},
}; };
Event::Start(container, attributes) if enter {
Event::Start(cont, attributes)
} else {
Event::End(cont)
} }
},
tree::EventKind::Exit(c) => match c {
block::Node::Leaf(l) => Event::End(Container::from_leaf_block(content, l)),
block::Node::Container(c) => {
let container = match c {
block::Container::Blockquote => Container::Blockquote,
block::Container::Div { .. } => Container::Div {
class: (!ev.span.is_empty()).then(|| content),
},
block::Container::Footnote => panic!(),
_ => panic!(),
};
Event::End(container)
} }
},
tree::EventKind::Inline => unreachable!(), tree::EventKind::Inline => unreachable!(),
}; };
return Some(event); return Some(event);