From 1b49ba1314711b83cc9a0fe225924770f029b866 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 7 Oct 2024 22:24:59 +0200 Subject: [PATCH] don't add a td if it's only used for styling --- src/paragraph/parser/mod.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/paragraph/parser/mod.rs b/src/paragraph/parser/mod.rs index 50c116d..c79a777 100644 --- a/src/paragraph/parser/mod.rs +++ b/src/paragraph/parser/mod.rs @@ -297,15 +297,19 @@ pub(crate) struct Td { absatz: Absatz, } impl Td { - pub(crate) fn parse(n: &Node) -> Self { + /// Returns `None` if td doesn't contain anything. used e.g. in ยง 71b to style table... + pub(crate) fn parse(n: &Node) -> Option { Expect::from(n).tag("td"); let mut c = n.children(); - let absatz = Absatz::parse(c.next().unwrap()); + + let Some(next) = c.next() else { return None }; + + let absatz = Absatz::parse(next); Expect::empty(c.next()); - Self { absatz } + Some(Self { absatz }) } } @@ -320,7 +324,9 @@ impl Tr { let mut tds = Vec::new(); for child in n.children() { - tds.push(Td::parse(&child)); + if let Some(td) = Td::parse(&child) { + tds.push(td); + } } Self { tds }