diff --git a/src/lib.rs b/src/lib.rs index 271aa1f..5c8ffa6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -293,6 +293,9 @@ pub struct Parser<'s> { /// Inline parser, recreated for each new inline. inline_parser: Option>>, + /// Stack of tightnesses for current open lists. + list_tightness: Vec, + /// 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)| { - matches!( - c, - block::Node::Container(block::Container::ListItem(..)) - ) && tree.linear().any(|elem| { + }) && !self.tree.linear_containers().any( + |(c, tree)| { matches!( - elem, - block::Element::Atom(block::Atom::Blankline) - ) - }) - }); + c, + 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, }), ); }