fixup! parser: determine tight vs loose lists

This commit is contained in:
Noah Hellman 2023-01-22 15:32:00 +01:00
parent 845c56fd0b
commit 69d51a5032

View file

@ -293,6 +293,9 @@ pub struct Parser<'s> {
/// Inline parser, recreated for each new inline.
inline_parser: Option<inline::Parser<span::InlineCharsIter<'s>>>,
/// Stack of tightnesses for current open lists.
list_tightness: Vec<bool>,
/// Footnote references in the order they were encountered, without duplicates.
footnote_references: Vec<&'s str>,
/// Cache of footnotes to emit at the end.
@ -333,6 +336,7 @@ impl<'s> Parser<'s> {
src,
link_definitions,
tree: branch,
list_tightness: Vec::new(),
footnote_references: Vec::new(),
footnotes: std::collections::HashMap::new(),
footnote_index: 0,
@ -521,20 +525,29 @@ impl<'s> Parser<'s> {
block::ListType::Task => ListKind::Task,
block::ListType::Description => unreachable!(),
};
let tight =
!self.tree.linear().any(|elem| {
let tight = if enter {
let tight = !self.tree.linear().any(|elem| {
matches!(elem, block::Element::Atom(block::Atom::Blankline))
}) && !self.tree.linear_containers().any(|(c, tree)| {
}) && !self.tree.linear_containers().any(
|(c, tree)| {
matches!(
c,
block::Node::Container(block::Container::ListItem(..))
block::Node::Container(block::Container::ListItem(
..
))
) && tree.linear().any(|elem| {
matches!(
elem,
block::Element::Atom(block::Atom::Blankline)
)
})
});
},
);
self.list_tightness.push(tight);
tight
} else {
self.list_tightness.pop().unwrap()
};
Container::List { kind, tight }
}
block::Container::ListItem(ty) => {
@ -1091,7 +1104,7 @@ mod test {
End(ListItem),
End(List {
kind: ListKind::Unordered,
tight: true,
tight: false,
}),
);
}