From 924a3c35bbb4a08477637cbbf75003b52cd73511 Mon Sep 17 00:00:00 2001 From: Noah Hellman Date: Wed, 10 May 2023 23:33:21 +0200 Subject: [PATCH] lib: make div class non option there is no distinction between an empty class and a None --- src/html.rs | 23 +++++++++++------------ src/lib.rs | 6 ++---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/html.rs b/src/html.rs index 9401571..b3c6985 100644 --- a/src/html.rs +++ b/src/html.rs @@ -208,14 +208,11 @@ impl<'s> Writer<'s> { if attrs.iter().any(|(a, _)| a == "class") || matches!( c, - Container::Div { class: Some(_) } - | Container::Math { .. } - | Container::List { - kind: ListKind::Task, - .. - } - | Container::TaskListItem { .. } - ) + Container::Div { class } if !class.is_empty()) + || matches!(c, |Container::Math { .. }| Container::List { + kind: ListKind::Task, + .. + } | Container::TaskListItem { .. }) { out.write_str(r#" class=""#)?; let mut first_written = false; @@ -246,11 +243,13 @@ impl<'s> Writer<'s> { .try_for_each(|part| write_attr(part, &mut out))?; } // div class goes after classes from attrs - if let Container::Div { class: Some(cls) } = c { - if first_written { - out.write_char(' ')?; + if let Container::Div { class } = c { + if !class.is_empty() { + if first_written { + out.write_char(' ')?; + } + out.write_str(class)?; } - out.write_str(cls)?; } out.write_char('"')?; } diff --git a/src/lib.rs b/src/lib.rs index c30bbd8..04da70c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -270,7 +270,7 @@ pub enum Container<'s> { /// A section belonging to a top level heading. Section { id: CowStr<'s> }, /// A block-level divider element. - Div { class: Option<&'s str> }, + Div { class: &'s str }, /// A paragraph. Paragraph, /// A heading. @@ -919,9 +919,7 @@ impl<'s> Parser<'s> { } 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::Div => Container::Div { class: content }, block::Container::Footnote => Container::Footnote { label: content }, block::Container::List(block::ListKind { ty, tight }) => { if matches!(ty, block::ListType::Description) {