diff --git a/crates/typst-realize/src/lib.rs b/crates/typst-realize/src/lib.rs index 754e89aac..50685a962 100644 --- a/crates/typst-realize/src/lib.rs +++ b/crates/typst-realize/src/lib.rs @@ -729,8 +729,8 @@ fn finish(s: &mut State) -> SourceResult<()> { } })?; - // In math, spaces are top-level. - if let RealizationKind::Math = s.kind { + // In paragraph and math realization, spaces are top-level. + if matches!(s.kind, RealizationKind::LayoutPar | RealizationKind::Math) { collapse_spaces(&mut s.sink, 0); } diff --git a/tests/ref/par-contains-block.png b/tests/ref/par-contains-block.png index f4bd071f6..27ca0cf6b 100644 Binary files a/tests/ref/par-contains-block.png and b/tests/ref/par-contains-block.png differ diff --git a/tests/ref/par-contains-parbreak.png b/tests/ref/par-contains-parbreak.png index f4bd071f6..27ca0cf6b 100644 Binary files a/tests/ref/par-contains-parbreak.png and b/tests/ref/par-contains-parbreak.png differ diff --git a/tests/ref/par-explicit-trim-space.png b/tests/ref/par-explicit-trim-space.png new file mode 100644 index 000000000..ff542274a Binary files /dev/null and b/tests/ref/par-explicit-trim-space.png differ diff --git a/tests/ref/par-show-children.png b/tests/ref/par-show-children.png new file mode 100644 index 000000000..bc81c5bdc Binary files /dev/null and b/tests/ref/par-show-children.png differ diff --git a/tests/ref/par-show-styles.png b/tests/ref/par-show-styles.png new file mode 100644 index 000000000..13a8065ad Binary files /dev/null and b/tests/ref/par-show-styles.png differ diff --git a/tests/ref/par-show.png b/tests/ref/par-show.png deleted file mode 100644 index 1ceb26f71..000000000 Binary files a/tests/ref/par-show.png and /dev/null differ diff --git a/tests/suite/model/par.typ b/tests/suite/model/par.typ index 84f2ec152..fa230451d 100644 --- a/tests/suite/model/par.typ +++ b/tests/suite/model/par.typ @@ -215,14 +215,16 @@ Welcome \ here. Does this work well? #set text(hyphenate: false) Lorem ipsum dolor #metadata(none) nonumy eirmod tempor. ---- par-show --- -// This is only slightly cursed. -#let revoke = metadata("revoke") +--- par-show-children --- +// Variant 1: Prevent recursion by checking the children. +#let p = counter("p") +#let step = p.step() +#let nr = context p.display() #show par: it => { - if bibliography.title == revoke { return it } - set bibliography(title: revoke) - let p = counter("p") - par[#p.step() §#context p.display() #it.body] + if it.body.at("children", default: ()).at(0, default: none) == step { + return it + } + par(step + [§#nr ] + it.body) } = A @@ -235,6 +237,27 @@ C #parbreak() D #block[F #parbreak() G] +--- par-show-styles --- +// Variant 2: Prevent recursion by observing a style. +#let revoke = metadata("revoke") +#show par: it => { + if bibliography.title == revoke { return it } + set bibliography(title: revoke) + let p = counter("p") + par[#p.step()§#context p.display() #it.body] +} + += A + +B + +C + +--- par-explicit-trim-space --- +A + +#par[ B ] + --- issue-4278-par-trim-before-equation --- #set par(justify: true) #lorem(6) aa $a = c + b$