Don't trim leading whitespace of anonymous table cells (#31803)

A sequence of whitespace shouldn't generate an anonymous table row/cell,
but we can't just throw away the leading whitespace, because afterwards
we may encounter some other content, and then the leading whitespace
should appear in the cell (noticeable with e.g. `white-space: pre`).
This commit is contained in:
Oriol Brufau 2024-03-21 12:48:39 +01:00 committed by GitHub
parent ce0d456469
commit ecabdc2583
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 19 additions and 29 deletions

View file

@ -56,6 +56,19 @@ pub(crate) enum AnonymousTableContent<'dom, Node> {
},
}
impl<'dom, Node> AnonymousTableContent<'dom, Node> {
fn is_whitespace_only(&self) -> bool {
match self {
Self::Element { .. } => false,
Self::Text(_, ref text) => text.chars().all(char_is_whitespace),
}
}
fn contents_are_whitespace_only(contents: &[Self]) -> bool {
contents.iter().all(|content| content.is_whitespace_only())
}
}
impl Table {
pub(crate) fn construct<'dom>(
context: &LayoutContext,
@ -627,7 +640,9 @@ where
}
fn finish_anonymous_row_if_needed(&mut self) {
if self.current_anonymous_row_content.is_empty() {
if AnonymousTableContent::contents_are_whitespace_only(&self.current_anonymous_row_content)
{
self.current_anonymous_row_content.clear();
return;
}
@ -689,9 +704,6 @@ where
Node: NodeExt<'dom>,
{
fn handle_text(&mut self, info: &NodeAndStyleInfo<Node>, text: Cow<'dom, str>) {
if text.chars().all(char_is_whitespace) {
return;
}
self.current_anonymous_row_content
.push(AnonymousTableContent::Text(info.clone(), text));
}
@ -897,7 +909,9 @@ where
}
fn finish_current_anonymous_cell_if_needed(&mut self) {
if self.current_anonymous_cell_content.is_empty() {
if AnonymousTableContent::contents_are_whitespace_only(&self.current_anonymous_cell_content)
{
self.current_anonymous_cell_content.clear();
return;
}
@ -947,9 +961,6 @@ where
Node: NodeExt<'dom>,
{
fn handle_text(&mut self, info: &NodeAndStyleInfo<Node>, text: Cow<'dom, str>) {
if text.chars().all(char_is_whitespace) {
return;
}
self.current_anonymous_cell_content
.push(AnonymousTableContent::Text(info.clone(), text));
}

View file

@ -1,2 +0,0 @@
[table-anonymous-objects-199.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table-anonymous-objects-200.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table-anonymous-objects-201.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table-anonymous-objects-202.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table-anonymous-objects-203.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table-anonymous-objects-204.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table-anonymous-objects-211.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[anonymous-table-ws-001.html]
expected: FAIL

View file

@ -14,8 +14,5 @@
[2.2. An anonymous table-row box must be generated around each sequence of consecutive children of a table-row-grouping box which are not table-row boxes. (3/3)]
expected: FAIL
[1.4. Anonymous inline boxes which contains only white space and are between two immediate siblings *each* of which is a table-non-root element, are treated as if they had display: none.]
expected: FAIL
[2.3 happens after 2.1. and 2.2. (1/2)]
expected: FAIL

View file

@ -1,2 +0,0 @@
[whitespace-001.html]
expected: FAIL