Fix Behaviour of spacing (#3634)

This commit is contained in:
Laurenz 2024-03-12 12:32:53 +01:00 committed by GitHub
parent 1d027ff6d2
commit 0fef857064
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 20 additions and 4 deletions

View File

@ -37,6 +37,8 @@ impl Show for Packed<MetadataElem> {
}
}
// TODO: Metadata shows as empty content, so this behaviour is unnecessary. It
// can be removed once 0.11 has landed.
impl Behave for Packed<MetadataElem> {
fn behaviour(&self) -> Behaviour {
Behaviour::Invisible

View File

@ -68,7 +68,7 @@ impl Behave for Packed<HElem> {
} else if self.weak(StyleChain::default()) {
Behaviour::Weak(1)
} else {
Behaviour::Invisible
Behaviour::Ignorant
}
}
@ -166,7 +166,7 @@ impl Behave for Packed<VElem> {
} else if self.weakness(StyleChain::default()) > 0 {
Behaviour::Weak(self.weakness(StyleChain::default()))
} else {
Behaviour::Invisible
Behaviour::Ignorant
}
}

View File

@ -16,9 +16,11 @@ pub enum Behaviour {
/// An element that destroys adjacent weak elements.
Destructive,
/// An element that does not interact at all with other elements, having the
/// same effect as if it didn't exist, but has a visual representation.
/// same effect as if it didn't exist, but has layout extent and/or a visual
/// representation.
Ignorant,
/// An element that does not have a visual representation.
/// An element that does not have any layout extent or visual
/// representation.
Invisible,
}

View File

@ -416,6 +416,9 @@ struct ParBuilder<'a>(BehavedBuilder<'a>);
impl<'a> ParBuilder<'a> {
fn accept(&mut self, content: &'a Content, styles: StyleChain<'a>) -> bool {
if content.is::<MetaElem>() {
// TODO: This could probably just be `self.0.is_empty()` since no
// weak or invisible elements can be at the start of the builder. It
// can be removed once 0.11 has landed.
if self.0.has_strong_elements(false) {
self.0.push(content, styles);
return true;

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 B

View File

@ -0,0 +1,9 @@
// Test that metadata after spacing does not force a new paragraph.
---
#{
h(1em)
counter(heading).update(4)
[Hello ]
counter(heading).display()
}