From 152132458e7bf405839a16d33b03d260c2a5387e Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 6 Nov 2025 07:13:58 -0800 Subject: [PATCH] Move end tag handling to a function This is to reduce the size of the processing function. --- crates/mdbook-html/src/html/tree.rs | 40 +++++++++++++++-------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/crates/mdbook-html/src/html/tree.rs b/crates/mdbook-html/src/html/tree.rs index 432cf7be..e4da7ef6 100644 --- a/crates/mdbook-html/src/html/tree.rs +++ b/crates/mdbook-html/src/html/tree.rs @@ -306,25 +306,7 @@ where trace!("event={event:?}"); match event { Event::Start(tag) => self.start_tag(tag), - Event::End(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::End(tag) => self.end_tag(tag), Event::Text(text) => { self.append_text(text.into_tendril()); } @@ -600,6 +582,26 @@ where 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 /// the current node. fn append_html(&mut self, html: &str) {