diff --git a/library/src/layout/par.rs b/library/src/layout/par.rs index 17e07cd0f..3385e0e74 100644 --- a/library/src/layout/par.rs +++ b/library/src/layout/par.rs @@ -318,7 +318,8 @@ impl Segment<'_> { Self::Text(len) => len, Self::Spacing(_) => SPACING_REPLACE.len_utf8(), Self::Box(_, true) => SPACING_REPLACE.len_utf8(), - Self::Equation(_) | Self::Box(_, _) | Self::Meta => OBJ_REPLACE.len_utf8(), + Self::Equation(_) | Self::Box(_, _) => OBJ_REPLACE.len_utf8(), + Self::Meta => 0, } } } @@ -334,6 +335,8 @@ enum Item<'a> { Fractional(Fr, Option<(&'a BoxElem, StyleChain<'a>)>), /// Layouted inline-level content. Frame(Frame), + /// Metadata. + Meta(Frame), } impl<'a> Item<'a> { @@ -351,6 +354,7 @@ impl<'a> Item<'a> { Self::Text(shaped) => shaped.text.len(), Self::Absolute(_) | Self::Fractional(_, _) => SPACING_REPLACE.len_utf8(), Self::Frame(_) => OBJ_REPLACE.len_utf8(), + Self::Meta(_) => 0, } } @@ -360,7 +364,7 @@ impl<'a> Item<'a> { Self::Text(shaped) => shaped.width, Self::Absolute(v) => *v, Self::Frame(frame) => frame.width(), - Self::Fractional(_, _) => Abs::zero(), + Self::Fractional(_, _) | Self::Meta(_) => Abs::zero(), } } } @@ -585,7 +589,6 @@ fn collect<'a>( full.push(if frac { SPACING_REPLACE } else { OBJ_REPLACE }); Segment::Box(elem, frac) } else if child.is::() { - full.push(OBJ_REPLACE); Segment::Meta } else { bail!(child.span(), "unexpected paragraph child"); @@ -670,7 +673,7 @@ fn prepare<'a>( Segment::Meta => { let mut frame = Frame::new(Size::zero()); frame.meta(styles, true); - items.push(Item::Frame(frame)); + items.push(Item::Meta(frame)); } } @@ -1336,7 +1339,7 @@ fn commit( let frame = shaped.build(vt, justification_ratio, extra_justification); push(&mut offset, frame); } - Item::Frame(frame) => { + Item::Frame(frame) | Item::Meta(frame) => { push(&mut offset, frame.clone()); } } diff --git a/tests/ref/meta/query-figure.png b/tests/ref/meta/query-figure.png new file mode 100644 index 000000000..3b8d3398e Binary files /dev/null and b/tests/ref/meta/query-figure.png differ diff --git a/tests/ref/meta/query-header.png b/tests/ref/meta/query-header.png new file mode 100644 index 000000000..809812020 Binary files /dev/null and b/tests/ref/meta/query-header.png differ diff --git a/tests/ref/meta/query.png b/tests/ref/meta/query.png deleted file mode 100644 index 7801d22bc..000000000 Binary files a/tests/ref/meta/query.png and /dev/null differ diff --git a/tests/ref/text/linebreak-obj.png b/tests/ref/text/linebreak-obj.png new file mode 100644 index 000000000..5fa250016 Binary files /dev/null and b/tests/ref/text/linebreak-obj.png differ diff --git a/tests/typ/meta/query.typ b/tests/typ/meta/query-figure.typ similarity index 57% rename from tests/typ/meta/query.typ rename to tests/typ/meta/query-figure.typ index 91325b61f..4b7307708 100644 --- a/tests/typ/meta/query.typ +++ b/tests/typ/meta/query-figure.typ @@ -1,35 +1,4 @@ -// Test the query function. - ---- -#set page( - paper: "a7", - margin: (y: 1cm, x: 0.5cm), - header: { - smallcaps[Typst Academy] - h(1fr) - locate(it => { - let after = query(selector(heading).after(it), it) - let before = query(selector(heading).before(it), it) - let elem = if before.len() != 0 { - before.last() - } else if after.len() != 0 { - after.first() - } - emph(elem.body) - }) - } -) - -#outline() - -= Introduction -#lorem(35) - -= Background -#lorem(35) - -= Approach -#lorem(60) +// Test a list of figures. --- #set page( diff --git a/tests/typ/meta/query-header.typ b/tests/typ/meta/query-header.typ new file mode 100644 index 000000000..dd83c1286 --- /dev/null +++ b/tests/typ/meta/query-header.typ @@ -0,0 +1,32 @@ +// Test creating a header with the query function. + +--- +#set page( + paper: "a7", + margin: (y: 1cm, x: 0.5cm), + header: { + smallcaps[Typst Academy] + h(1fr) + locate(it => { + let after = query(selector(heading).after(it), it) + let before = query(selector(heading).before(it), it) + let elem = if before.len() != 0 { + before.last() + } else if after.len() != 0 { + after.first() + } + emph(elem.body) + }) + } +) + +#outline() + += Introduction +#lorem(35) + += Background +#lorem(35) + += Approach +#lorem(60) diff --git a/tests/typ/text/linebreak-obj.typ b/tests/typ/text/linebreak-obj.typ new file mode 100644 index 000000000..bd3b69ae9 --- /dev/null +++ b/tests/typ/text/linebreak-obj.typ @@ -0,0 +1,18 @@ +// Test linebreaks with after inline elements. + +--- +// Test punctuation after citations. +#set page(width: 162pt) + +They can look for the details in @netwok, +which is the authorative source. + +#bibliography("/works.bib") + +--- +// Test punctuation after math equations. +#set page(width: 85pt) + +We prove $1 < 2$. \ +We prove $1 < 2$! \ +We prove $1 < 2$– \