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
61
src/lib.rs
61
src/lib.rs
|
@ -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 {
|
||||||
// ignore link definitions
|
block::Node::Leaf(l) => {
|
||||||
self.tree.take_inlines().last();
|
if matches!(l, block::Leaf::LinkDefinition) {
|
||||||
continue;
|
// ignore link definitions
|
||||||
}
|
self.tree.take_inlines().last();
|
||||||
tree::EventKind::Enter(c) => match c {
|
continue;
|
||||||
block::Node::Leaf(l) => {
|
}
|
||||||
self.inlines.set_spans(self.tree.take_inlines());
|
if enter {
|
||||||
self.inline_parser = Some(inline::Parser::new(self.inlines.chars()));
|
self.inlines.set_spans(self.tree.take_inlines());
|
||||||
let container = Container::from_leaf_block(content, l);
|
self.inline_parser =
|
||||||
Event::Start(container, attributes)
|
Some(inline::Parser::new(self.inlines.chars()));
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
|
Loading…
Reference in a new issue