lib: make div class non option
there is no distinction between an empty class and a None
This commit is contained in:
parent
116fb04725
commit
924a3c35bb
2 changed files with 13 additions and 16 deletions
23
src/html.rs
23
src/html.rs
|
@ -208,14 +208,11 @@ impl<'s> Writer<'s> {
|
||||||
if attrs.iter().any(|(a, _)| a == "class")
|
if attrs.iter().any(|(a, _)| a == "class")
|
||||||
|| matches!(
|
|| matches!(
|
||||||
c,
|
c,
|
||||||
Container::Div { class: Some(_) }
|
Container::Div { class } if !class.is_empty())
|
||||||
| Container::Math { .. }
|
|| matches!(c, |Container::Math { .. }| Container::List {
|
||||||
| Container::List {
|
kind: ListKind::Task,
|
||||||
kind: ListKind::Task,
|
..
|
||||||
..
|
} | Container::TaskListItem { .. })
|
||||||
}
|
|
||||||
| Container::TaskListItem { .. }
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
out.write_str(r#" class=""#)?;
|
out.write_str(r#" class=""#)?;
|
||||||
let mut first_written = false;
|
let mut first_written = false;
|
||||||
|
@ -246,11 +243,13 @@ impl<'s> Writer<'s> {
|
||||||
.try_for_each(|part| write_attr(part, &mut out))?;
|
.try_for_each(|part| write_attr(part, &mut out))?;
|
||||||
}
|
}
|
||||||
// div class goes after classes from attrs
|
// div class goes after classes from attrs
|
||||||
if let Container::Div { class: Some(cls) } = c {
|
if let Container::Div { class } = c {
|
||||||
if first_written {
|
if !class.is_empty() {
|
||||||
out.write_char(' ')?;
|
if first_written {
|
||||||
|
out.write_char(' ')?;
|
||||||
|
}
|
||||||
|
out.write_str(class)?;
|
||||||
}
|
}
|
||||||
out.write_str(cls)?;
|
|
||||||
}
|
}
|
||||||
out.write_char('"')?;
|
out.write_char('"')?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,7 +270,7 @@ pub enum Container<'s> {
|
||||||
/// A section belonging to a top level heading.
|
/// A section belonging to a top level heading.
|
||||||
Section { id: CowStr<'s> },
|
Section { id: CowStr<'s> },
|
||||||
/// A block-level divider element.
|
/// A block-level divider element.
|
||||||
Div { class: Option<&'s str> },
|
Div { class: &'s str },
|
||||||
/// A paragraph.
|
/// A paragraph.
|
||||||
Paragraph,
|
Paragraph,
|
||||||
/// A heading.
|
/// A heading.
|
||||||
|
@ -919,9 +919,7 @@ impl<'s> Parser<'s> {
|
||||||
}
|
}
|
||||||
block::Node::Container(c) => 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: content },
|
||||||
class: (!ev.span.is_empty()).then(|| content),
|
|
||||||
},
|
|
||||||
block::Container::Footnote => Container::Footnote { label: content },
|
block::Container::Footnote => Container::Footnote { label: content },
|
||||||
block::Container::List(block::ListKind { ty, tight }) => {
|
block::Container::List(block::ListKind { ty, tight }) => {
|
||||||
if matches!(ty, block::ListType::Description) {
|
if matches!(ty, block::ListType::Description) {
|
||||||
|
|
Loading…
Reference in a new issue