fixup! parser: determine tight vs loose lists
This commit is contained in:
parent
845c56fd0b
commit
69d51a5032
1 changed files with 26 additions and 13 deletions
39
src/lib.rs
39
src/lib.rs
|
@ -293,6 +293,9 @@ pub struct Parser<'s> {
|
||||||
/// Inline parser, recreated for each new inline.
|
/// Inline parser, recreated for each new inline.
|
||||||
inline_parser: Option<inline::Parser<span::InlineCharsIter<'s>>>,
|
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 in the order they were encountered, without duplicates.
|
||||||
footnote_references: Vec<&'s str>,
|
footnote_references: Vec<&'s str>,
|
||||||
/// Cache of footnotes to emit at the end.
|
/// Cache of footnotes to emit at the end.
|
||||||
|
@ -333,6 +336,7 @@ impl<'s> Parser<'s> {
|
||||||
src,
|
src,
|
||||||
link_definitions,
|
link_definitions,
|
||||||
tree: branch,
|
tree: branch,
|
||||||
|
list_tightness: Vec::new(),
|
||||||
footnote_references: Vec::new(),
|
footnote_references: Vec::new(),
|
||||||
footnotes: std::collections::HashMap::new(),
|
footnotes: std::collections::HashMap::new(),
|
||||||
footnote_index: 0,
|
footnote_index: 0,
|
||||||
|
@ -521,20 +525,29 @@ impl<'s> Parser<'s> {
|
||||||
block::ListType::Task => ListKind::Task,
|
block::ListType::Task => ListKind::Task,
|
||||||
block::ListType::Description => unreachable!(),
|
block::ListType::Description => unreachable!(),
|
||||||
};
|
};
|
||||||
let tight =
|
let tight = if enter {
|
||||||
!self.tree.linear().any(|elem| {
|
let tight = !self.tree.linear().any(|elem| {
|
||||||
matches!(elem, block::Element::Atom(block::Atom::Blankline))
|
matches!(elem, block::Element::Atom(block::Atom::Blankline))
|
||||||
}) && !self.tree.linear_containers().any(|(c, tree)| {
|
}) && !self.tree.linear_containers().any(
|
||||||
matches!(
|
|(c, tree)| {
|
||||||
c,
|
|
||||||
block::Node::Container(block::Container::ListItem(..))
|
|
||||||
) && tree.linear().any(|elem| {
|
|
||||||
matches!(
|
matches!(
|
||||||
elem,
|
c,
|
||||||
block::Element::Atom(block::Atom::Blankline)
|
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 }
|
Container::List { kind, tight }
|
||||||
}
|
}
|
||||||
block::Container::ListItem(ty) => {
|
block::Container::ListItem(ty) => {
|
||||||
|
@ -1091,7 +1104,7 @@ mod test {
|
||||||
End(ListItem),
|
End(ListItem),
|
||||||
End(List {
|
End(List {
|
||||||
kind: ListKind::Unordered,
|
kind: ListKind::Unordered,
|
||||||
tight: true,
|
tight: false,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue