parse: merge enter / exit block events match branch
This commit is contained in:
parent
50632204a3
commit
6befcad52a
1 changed files with 27 additions and 34 deletions
45
src/lib.rs
45
src/lib.rs
|
@ -456,49 +456,42 @@ impl<'s> Parser<'s> {
|
|||
continue;
|
||||
}
|
||||
},
|
||||
tree::EventKind::Enter(c) | tree::EventKind::Exit(c)
|
||||
if matches!(c, block::Node::Leaf(block::Leaf::LinkDefinition)) =>
|
||||
{
|
||||
tree::EventKind::Enter(c) | tree::EventKind::Exit(c) => {
|
||||
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
|
||||
self.tree.take_inlines().last();
|
||||
continue;
|
||||
}
|
||||
tree::EventKind::Enter(c) => match c {
|
||||
block::Node::Leaf(l) => {
|
||||
if enter {
|
||||
self.inlines.set_spans(self.tree.take_inlines());
|
||||
self.inline_parser = Some(inline::Parser::new(self.inlines.chars()));
|
||||
let container = Container::from_leaf_block(content, l);
|
||||
Event::Start(container, attributes)
|
||||
self.inline_parser =
|
||||
Some(inline::Parser::new(self.inlines.chars()));
|
||||
}
|
||||
block::Node::Container(c) => {
|
||||
let container = match c {
|
||||
Container::from_leaf_block(content, l)
|
||||
}
|
||||
block::Node::Container(c) => match c {
|
||||
block::Container::Blockquote => Container::Blockquote,
|
||||
block::Container::Div { .. } => Container::Div {
|
||||
class: (!ev.span.is_empty()).then(|| content),
|
||||
},
|
||||
block::Container::Footnote => {
|
||||
assert!(enter);
|
||||
self.footnotes.insert(content, self.tree.take_branch());
|
||||
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!(),
|
||||
};
|
||||
return Some(event);
|
||||
|
|
Loading…
Reference in a new issue