mirror of
https://github.com/servo/servo.git
synced 2025-08-02 12:10:29 +01:00
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:
parent
ce0d456469
commit
ecabdc2583
11 changed files with 19 additions and 29 deletions
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue