mirror of
https://github.com/rust-lang/mdBook.git
synced 2025-12-27 10:16:09 -05:00
Move end tag handling to a function
This is to reduce the size of the processing function.
This commit is contained in:
@@ -306,25 +306,7 @@ where
|
|||||||
trace!("event={event:?}");
|
trace!("event={event:?}");
|
||||||
match event {
|
match event {
|
||||||
Event::Start(tag) => self.start_tag(tag),
|
Event::Start(tag) => self.start_tag(tag),
|
||||||
Event::End(tag) => {
|
Event::End(tag) => self.end_tag(tag),
|
||||||
// TODO: This should validate that the event stack is
|
|
||||||
// properly synchronized with the tag stack.
|
|
||||||
self.pop();
|
|
||||||
match tag {
|
|
||||||
TagEnd::TableHead => {
|
|
||||||
self.table_state = TableState::Body;
|
|
||||||
self.push(Node::Element(Element::new("tbody")));
|
|
||||||
}
|
|
||||||
TagEnd::TableCell => {
|
|
||||||
self.table_cell_index += 1;
|
|
||||||
}
|
|
||||||
TagEnd::Table => {
|
|
||||||
// Pop tbody or thead
|
|
||||||
self.pop();
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Event::Text(text) => {
|
Event::Text(text) => {
|
||||||
self.append_text(text.into_tendril());
|
self.append_text(text.into_tendril());
|
||||||
}
|
}
|
||||||
@@ -600,6 +582,26 @@ where
|
|||||||
self.push(Node::Element(element));
|
self.push(Node::Element(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn end_tag(&mut self, tag: TagEnd) {
|
||||||
|
// TODO: This should validate that the event stack is
|
||||||
|
// properly synchronized with the tag stack.
|
||||||
|
self.pop();
|
||||||
|
match tag {
|
||||||
|
TagEnd::TableHead => {
|
||||||
|
self.table_state = TableState::Body;
|
||||||
|
self.push(Node::Element(Element::new("tbody")));
|
||||||
|
}
|
||||||
|
TagEnd::TableCell => {
|
||||||
|
self.table_cell_index += 1;
|
||||||
|
}
|
||||||
|
TagEnd::Table => {
|
||||||
|
// Pop tbody or thead
|
||||||
|
self.pop();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Given some HTML, parse it into [`Node`] elements and append them to
|
/// Given some HTML, parse it into [`Node`] elements and append them to
|
||||||
/// the current node.
|
/// the current node.
|
||||||
fn append_html(&mut self, html: &str) {
|
fn append_html(&mut self, html: &str) {
|
||||||
|
|||||||
Reference in New Issue
Block a user