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!
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
Pull request: https://github.com/WebKit/WebKit/pull/738
<rdar://problem/93887979>
Any news on this? A pull request was filed but nothing since?