Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/dom/elements/the-innertext-and-outertext-properties/innertext-whitespace-pre-line.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>innerText with white-space:pre-line</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="a" style="white-space: pre-line">one two three four</div>
<div id="b" style="white-space: pre">one two three four</div>
<div id="c" style="white-space: pre-line">
one
two
<!-- comment -->
three
four
</div>
<div id="d" style="white-space: pre">
one
two
<!-- comment -->
three
four
</div>
<script>
test(() => {
assert_equals(a.innerText, b.innerText);
}, "innerText should be the same for the pre-line and pre examples");
test(() => {
function collapseWhitespace(s) {
return s.replace(/ +/g, ' ') // collapse runs of spaces
.replace(/ $/mg, '') // strip trailing spaces
.replace(/^ /mg, ''); // strip leading spaces
}
assert_equals(c.innerText, collapseWhitespace(d.innerText));
}, "innerText has collapsed whitespace but preserved newlines with pre-line");
</script>