diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index dbf56c86b77..244aa34b24f 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -1501,10 +1501,17 @@ impl Fragment { } } - /// Returns true if this fragment is an unscanned text fragment that consists entirely of whitespace. - pub fn is_whitespace_only(&self) -> bool { + /// Returns true if this fragment is an unscanned text fragment that consists entirely of + /// whitespace that should be stripped. + pub fn is_ignorable_whitespace(&self) -> bool { + match self.white_space() { + white_space::pre => return false, + white_space::normal | white_space::nowrap => {} + } match self.specific { - UnscannedTextFragment(ref text_fragment_info) => is_whitespace(text_fragment_info.text.as_slice()), + UnscannedTextFragment(ref text_fragment_info) => { + is_whitespace(text_fragment_info.text.as_slice()) + } _ => false, } } diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 86522e1d958..700ffa56602 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -708,7 +708,7 @@ impl InlineFragments { let mut new_fragments = Vec::new(); let mut skipping = true; for fragment in fragments { - if skipping && fragment.is_whitespace_only() { + if skipping && fragment.is_ignorable_whitespace() { debug!("stripping ignorable whitespace from start"); continue } @@ -727,7 +727,8 @@ impl InlineFragments { } let mut new_fragments = self.fragments.clone(); - while new_fragments.len() > 0 && new_fragments.as_slice().last().as_ref().unwrap().is_whitespace_only() { + while new_fragments.len() > 0 && + new_fragments.as_slice().last().as_ref().unwrap().is_ignorable_whitespace() { debug!("stripping ignorable whitespace from end"); drop(new_fragments.pop()); } diff --git a/tests/ref/basic.list b/tests/ref/basic.list index 0a59a793e78..e3b432b8257 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -165,3 +165,4 @@ fragment=top != ../html/acid2.html acid2_ref.html == inline_hypothetical_box_a.html inline_hypothetical_box_ref.html == box_sizing_border_box_a.html box_sizing_border_box_ref.html != input_height_a.html input_height_ref.html +== pre_ignorable_whitespace_a.html pre_ignorable_whitespace_ref.html diff --git a/tests/ref/pre_ignorable_whitespace_a.html b/tests/ref/pre_ignorable_whitespace_a.html new file mode 100644 index 00000000000..af9eb6ad441 --- /dev/null +++ b/tests/ref/pre_ignorable_whitespace_a.html @@ -0,0 +1,7 @@ + + + +yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + + diff --git a/tests/ref/pre_ignorable_whitespace_ref.html b/tests/ref/pre_ignorable_whitespace_ref.html new file mode 100644 index 00000000000..48ffe0dd06f --- /dev/null +++ b/tests/ref/pre_ignorable_whitespace_ref.html @@ -0,0 +1,7 @@ + + + +yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + +