File: whitespace.html

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (62 lines) | stat: -rw-r--r-- 2,183 bytes parent folder | download | duplicates (28)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!doctype html>
<title>CSS Whitespace</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<meta name="author" title="Tab Atkins-Bittner">
<link rel=help href="https://drafts.csswg.org/css-syntax/#whitespace">

<div class=a><b></b></div>
<div id=foo></div>

<!--
CSS's definition of "whitespace" matches HTML,
and includes only the five ASCII characters
U+0009, U+000A, U+000C, U+000D, and U+0020.
The rest of Unicode's whitespace characters,
many of which are recognized as whitespace by JS,
are not valid whitespace in CSS.
-->

<script>

function isWhitespace(codepoint) {
    const char = String.fromCodePoint(codepoint);
    const codepointName = "U+" + codepoint.toString(16).padStart(4, "0");
    test(()=>{
        const withSpace = document.querySelector(".a b");
        const withChar = document.querySelector(`.a${char}b`);
        assert_equals(withSpace, withChar);
    }, `${codepointName} is CSS whitespace`);
}
function isNotWhitespace(codepoint) {
    const char = String.fromCodePoint(codepoint);
    const codepointName = "U+" + codepoint.toString(16).padStart(4, "0");
    test(()=>{
        const withSpace = document.querySelector(".a b");
        document.querySelector("#foo").setAttribute("class", `.a${char}b`);
        try {
            var withChar = document.querySelector(`.a${char}b`);
        } catch(e) {
            assert_true(true, `${codepointName} isn't valid in a selector at all`);
            return;
        }
        assert_not_equals(withSpace, withChar);
    }, `${codepointName} is *not* CSS whitespace`);
}

// CSS Whitespace characters
var whitespace = [0x9, 0xa, 0xc, 0xd, 0x20];

// Unicode Whitespace characters not recognized by CSS
// https://en.wikipedia.org/wiki/Whitespace_character#Unicode
var notWhitespace = [0xb, 0x85, 0xa0, 0x1680, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200a, 0x2928, 0x2029, 0x202f, 0x205f, 0x3000, 0x180e, 0x200b, 0x200c, 0x200d, 0x2060, 0xfeff];

for(var codepoint of whitespace) {
    isWhitespace(codepoint);
}
for(var codepoint of notWhitespace) {
    isNotWhitespace(codepoint);
}

</script>