Full support for the CSS `white-space` property
bugenhancementC-parley
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.
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.
```rust
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)
```rust
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](https://docs.rs/parley/latest/parley/style/enum.WhiteSpaceCollapse.html) only the `Collapse` and `Preserve` variants in a somewhat hacky way [in the `TreeBuilder`](https://docs.rs/parley/latest/parley/struct.TreeBuilder.html#method.set_white_space_mode), 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 https://github.com/linebender/parley/pull/485 which attempted fixes for whitespace hanging behaviour.
#### `white-space-trim`
Controls "whitespace trimming" at the beggining and end of spans.
```rust
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.
0 条评论