Skip to content

DRAFT: Better white space collapse#680

Draft
nicoburns wants to merge 5 commits into
linebender:mainfrom
nicoburns:better-white-space-collapse
Draft

DRAFT: Better white space collapse#680
nicoburns wants to merge 5 commits into
linebender:mainfrom
nicoburns:better-white-space-collapse

Conversation

@nicoburns

@nicoburns nicoburns commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Implements the white-space-collapse portion of:

Generated with Opus 4.8 High, with review/revisions from Fable. Some manual review has been done. More coming soon (before this is moved out of draft).

Changes made

  • Add PreserveBreaks, PreserveSpaces, and BreakSpaces variants to WhiteSpaceCollapse.
  • Implement the actual whitespace collapsing behaviour for these modes in the TreeBuilder
    (+ optimize the whitespace-collapsing in the TreeBuilder to reuse a single buffer in-place rather than constructing a new string for every span (simple local refactor)).
  • For BreakSpaces, generate additional soft line-breaking opportunities. This is implemented within the line-breaking code rather than in the analysis.
  • Implement the different "hanging" behaviour for the various white-space-collapse modes.
  • Account for the differences in min/max content widths of the various whitespace-collapsing modes (if whitespace hangs that contributes differently to the content widths than if it doesn't hang)

^ The last change is the cause of the snapshot changes, which look like an improvement to me: in the changed layouts, Parley's computed content width now tightly wrapping it's content rather than including trailing whitespace.

I also have some follow-ups (not included here) that:

  • Fix the "trimming" behaviour of the whitespace collapsing. Whitespace was previously being trimmed at the start/end of every inline span, but it should only be trimmed at the start/end of the entire layout/paragraph.
  • Make WhiteSpaceCollapse a style rather than a weird out-of-band method on the TreeBuilder

See: https://github.com/nicoburns/parley/tree/with-whitespace-style for a branch that includes those changes

nicoburns added 5 commits July 8, 2026 19:39
Signed-off-by: Nico Burns <nico@nicoburns.com>
Signed-off-by: Nico Burns <nico@nicoburns.com>
Signed-off-by: Nico Burns <nico@nicoburns.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant