diff options
| author | Laurenz <laurmaedje@gmail.com> | 2025-01-24 13:31:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-24 12:31:03 +0000 |
| commit | 176b070c779ef8aa4515c8ff062b17ca9114fd3f (patch) | |
| tree | e8914eda708f508e17428549862bce8ea44d38d9 | |
| parent | 26e65bfef5b1da7f6c72e1409237cf03fb5d6069 (diff) | |
Fix space collapsing for explicit paragraphs (#5749)
| -rw-r--r-- | crates/typst-realize/src/lib.rs | 4 | ||||
| -rw-r--r-- | tests/ref/par-contains-block.png | bin | 426 -> 423 bytes | |||
| -rw-r--r-- | tests/ref/par-contains-parbreak.png | bin | 426 -> 423 bytes | |||
| -rw-r--r-- | tests/ref/par-explicit-trim-space.png | bin | 0 -> 215 bytes | |||
| -rw-r--r-- | tests/ref/par-show-children.png | bin | 0 -> 920 bytes | |||
| -rw-r--r-- | tests/ref/par-show-styles.png | bin | 0 -> 471 bytes | |||
| -rw-r--r-- | tests/ref/par-show.png | bin | 932 -> 0 bytes | |||
| -rw-r--r-- | tests/suite/model/par.typ | 35 |
8 files changed, 31 insertions, 8 deletions
diff --git a/crates/typst-realize/src/lib.rs b/crates/typst-realize/src/lib.rs index 754e89aa..50685a96 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 Binary files differindex f4bd071f..27ca0cf6 100644 --- a/tests/ref/par-contains-block.png +++ b/tests/ref/par-contains-block.png diff --git a/tests/ref/par-contains-parbreak.png b/tests/ref/par-contains-parbreak.png Binary files differindex f4bd071f..27ca0cf6 100644 --- a/tests/ref/par-contains-parbreak.png +++ b/tests/ref/par-contains-parbreak.png diff --git a/tests/ref/par-explicit-trim-space.png b/tests/ref/par-explicit-trim-space.png Binary files differnew file mode 100644 index 00000000..ff542274 --- /dev/null +++ b/tests/ref/par-explicit-trim-space.png diff --git a/tests/ref/par-show-children.png b/tests/ref/par-show-children.png Binary files differnew file mode 100644 index 00000000..bc81c5bd --- /dev/null +++ b/tests/ref/par-show-children.png diff --git a/tests/ref/par-show-styles.png b/tests/ref/par-show-styles.png Binary files differnew file mode 100644 index 00000000..13a8065a --- /dev/null +++ b/tests/ref/par-show-styles.png diff --git a/tests/ref/par-show.png b/tests/ref/par-show.png Binary files differdeleted file mode 100644 index 1ceb26f7..00000000 --- a/tests/ref/par-show.png +++ /dev/null diff --git a/tests/suite/model/par.typ b/tests/suite/model/par.typ index 84f2ec15..fa230451 100644 --- a/tests/suite/model/par.typ +++ b/tests/suite/model/par.typ @@ -215,25 +215,48 @@ 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. +--- 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 it.body.at("children", default: ()).at(0, default: none) == step { + return it + } + par(step + [§#nr ] + it.body) +} + += A + +B + +C #parbreak() D + +#block[E] + +#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] + par[#p.step()§#context p.display() #it.body] } = A B -C #parbreak() D +C -#block[E] +--- par-explicit-trim-space --- +A -#block[F #parbreak() G] +#par[ B ] --- issue-4278-par-trim-before-equation --- #set par(justify: true) |
