Skip to content

Full support for the CSS white-space property #619

Description

@nicoburns

The CSS white-space property is defined in sections 3 and 4 of the css-text-4 specification: https://drafts.csswg.org/css-text-4/#white-space-property. It is a very important property for accurately reproducing how browsers lay out text. And can also be used to account for differences between desired behaviour between editable and non-editable text around how whitespace is "hung" at the end of lines.

(the emojis in this issue were not generated by AI)

It is considered a "shorthand" property that decomposes into the following longhands:

text-wrap-mode

This property has two variants: wrap and nowrap. nowrap disables wrapping entirely.

enum TextWrapMode {
     Wrap,
     NoWrap,
}

Status: fully implemented.

⚠️ white-space-collapse

This property controls:

  • ⚠️ How whitespace is collapsed
  • ❌ How whitespace at the end of the line is "hung" (or not hung)
enum WhiteSpaceCollapse {
      Collapse,
      Discard,
      Preserve,
      PreserveBreaks,
      PreserveSpaces,
      BreakSpaces,
}

See spec (https://drafts.csswg.org/css-text-4/#white-space-collapsing) for the meanings of each variant.

Status: we currently implement only the Collapse and Preserve variants in a somewhat hacky way in the TreeBuilder, and we also only implement the "white space collapsing" behaviour, and do not implement the different "whitespace hanging" behaviours (implementing the latter will require us to pass WhiteSpaceCollapse into layout as a style which we do not currently do).

See also: discussion on #485 which attempted fixes for whitespace hanging behaviour.

⚠️ white-space-trim

Controls "whitespace trimming" at the beggining and end of spans.

enum WhiteSpaceCollapse {
      DiscardBefore,
      DiscardAfter,
      DiscardInner,
}

Status: some basic trimming is implemented hackily in the TreeBuilder, but there are bugs in the current implementation. And it also doesn't allow full control over the trimming using a style.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-parleyRelates to the parley cratebugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions