WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
240566
innerText from element with "white-space: pre-line" incorrectly removes line breaks
https://bugs.webkit.org/show_bug.cgi?id=240566
Summary
innerText from element with "white-space: pre-line" incorrectly removes line ...
ik
Reported
2022-05-18 01:41:29 PDT
Created
attachment 459530
[details]
Testcase v101 When I retrieve the innerText value of an element that has "white-space: pre-line;", the resulting string does not contain any line breaks (\n). The following changes/variations do preserve line breaks when retrieving : * Retrieving textContent instead of innerText * Using "pre-wrap" * A combination of the above ... but these have side-effects, as it causes slightly different behavior. According to MDN, newlines should be preserved for both pre-line and pre-wrap:
https://developer.mozilla.org/en-US/docs/Web/CSS/white-space#values
See attached testcase, also available here:
https://testcase.rejh.nl/webkit-pre-line-innertext/
* The first div has "white-space: pre-line" * The second div has "pre-wrap" * Use the buttons to print innerText or textContent to the console Note: I've tested this in Safari, Chrome and Firefox. Only Chrome returns the same result for innerText and textContent when "pre-line" is set, preserving line breaks. Firefox seems to also strip the newline characters when retrieving innerText while preserving them for textContent. If the intended/spec'd behavior of innerText is to remove line breaks for "pre-line", I'll happily file a bug @ Chrome :) Thanks!
Attachments
Testcase v101
(1.20 KB, application/x-zip-compressed)
2022-05-18 01:41 PDT
,
ik
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Sam Sneddon [:gsnedders]
Comment 1
2022-05-18 10:06:43 PDT
https://html.spec.whatwg.org/multipage/dom.html#rendered-text-collection-steps
says:
> If node is a Text node, then for each CSS text box produced by node, in content order, compute the text of the box after application of the CSS 'white-space' processing rules and 'text-transform' rules, set items to the list of the resulting strings, and return items. The CSS 'white-space' processing rules are slightly modified: collapsible spaces at the end of lines are always collapsed, but they are only removed if the line is the last line of the block, or it ends with a br element. Soft hyphens should be preserved. [CSSTEXT]
This implies that pre-line should be preserve the new lines. Not looked closely at Firefox, but it seems Safari is the only browser failing the '\n preserved ("<div style='white-space:pre-line'>abc\ndef")' subtest at
https://wpt.fyi/results/html/dom/elements/the-innertext-and-outertext-properties/getter.html?label=master&label=experimental&product=chrome&product=firefox&product=safari&aligned
Chris Dumez
Comment 2
2022-05-18 11:41:56 PDT
Pull request:
https://github.com/WebKit/WebKit/pull/738
Radar WebKit Bug Importer
Comment 3
2022-05-25 01:42:14 PDT
<
rdar://problem/93887979
>
ik
Comment 4
2022-12-14 12:21:49 PST
Any news on this? A pull request was filed but nothing since?
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug