parse5 0.6.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/.npmignore +3 -1
  2. package/LICENSE +1 -1
  3. package/README.md +166 -77
  4. package/index.js +7 -0
  5. package/lib/{html.js → const/html.js} +0 -0
  6. package/lib/{unicode.js → const/unicode.js} +0 -0
  7. package/lib/{named_entity_trie.js → tokenization_stage/named_entity_trie.js} +1 -1
  8. package/lib/tokenization_stage/parser_simulator.js +2 -0
  9. package/lib/{preprocessor.js → tokenization_stage/preprocessor.js} +5 -5
  10. package/lib/{tokenizer.js → tokenization_stage/tokenizer.js} +37 -37
  11. package/lib/{default_tree_adapter.js → tree_adapters/default.js} +47 -0
  12. package/lib/tree_adapters/htmlparser2.js +267 -0
  13. package/lib/{formatting_element_list.js → tree_construction_stage/formatting_element_list.js} +1 -1
  14. package/lib/{open_element_stack.js → tree_construction_stage/open_element_stack.js} +2 -2
  15. package/lib/{parser.js → tree_construction_stage/parser.js} +8 -8
  16. package/lib/tree_construction_stage/tree_serializer.js +165 -0
  17. package/package.json +33 -26
  18. package/test/data/tokenizer/contentModelFlags.test +0 -75
  19. package/test/data/tokenizer/domjs.test +0 -90
  20. package/test/data/tokenizer/entities.test +0 -283
  21. package/test/data/tokenizer/escapeFlag.test +0 -33
  22. package/test/data/tokenizer/namedEntities.test +0 -44189
  23. package/test/data/tokenizer/numericEntities.test +0 -1313
  24. package/test/data/tokenizer/pendingSpecChanges.test +0 -7
  25. package/test/data/tokenizer/test1.test +0 -196
  26. package/test/data/tokenizer/test2.test +0 -179
  27. package/test/data/tokenizer/test3.test +0 -6047
  28. package/test/data/tokenizer/test4.test +0 -344
  29. package/test/data/tokenizer/unicodeChars.test +0 -1295
  30. package/test/data/tokenizer/unicodeCharsProblematic.test +0 -27
  31. package/test/data/tree-construction/adoption01.dat +0 -275
  32. package/test/data/tree-construction/adoption02.dat +0 -31
  33. package/test/data/tree-construction/comments01.dat +0 -146
  34. package/test/data/tree-construction/doctype01.dat +0 -370
  35. package/test/data/tree-construction/domjs-unsafe.dat +0 -0
  36. package/test/data/tree-construction/entities01.dat +0 -603
  37. package/test/data/tree-construction/entities02.dat +0 -249
  38. package/test/data/tree-construction/html5test-com.dat +0 -246
  39. package/test/data/tree-construction/inbody01.dat +0 -43
  40. package/test/data/tree-construction/isindex.dat +0 -40
  41. package/test/data/tree-construction/main-element.dat +0 -29
  42. package/test/data/tree-construction/pending-spec-changes-plain-text-unsafe.dat +0 -0
  43. package/test/data/tree-construction/pending-spec-changes.dat +0 -52
  44. package/test/data/tree-construction/plain-text-unsafe.dat +0 -0
  45. package/test/data/tree-construction/scriptdata01.dat +0 -308
  46. package/test/data/tree-construction/tables01.dat +0 -212
  47. package/test/data/tree-construction/tests1.dat +0 -1952
  48. package/test/data/tree-construction/tests10.dat +0 -799
  49. package/test/data/tree-construction/tests11.dat +0 -482
  50. package/test/data/tree-construction/tests12.dat +0 -62
  51. package/test/data/tree-construction/tests14.dat +0 -74
  52. package/test/data/tree-construction/tests15.dat +0 -208
  53. package/test/data/tree-construction/tests16.dat +0 -2299
  54. package/test/data/tree-construction/tests17.dat +0 -153
  55. package/test/data/tree-construction/tests18.dat +0 -269
  56. package/test/data/tree-construction/tests19.dat +0 -1249
  57. package/test/data/tree-construction/tests2.dat +0 -763
  58. package/test/data/tree-construction/tests20.dat +0 -455
  59. package/test/data/tree-construction/tests21.dat +0 -257
  60. package/test/data/tree-construction/tests22.dat +0 -157
  61. package/test/data/tree-construction/tests23.dat +0 -155
  62. package/test/data/tree-construction/tests24.dat +0 -79
  63. package/test/data/tree-construction/tests25.dat +0 -219
  64. package/test/data/tree-construction/tests26.dat +0 -313
  65. package/test/data/tree-construction/tests3.dat +0 -305
  66. package/test/data/tree-construction/tests4.dat +0 -59
  67. package/test/data/tree-construction/tests5.dat +0 -191
  68. package/test/data/tree-construction/tests6.dat +0 -663
  69. package/test/data/tree-construction/tests7.dat +0 -390
  70. package/test/data/tree-construction/tests8.dat +0 -148
  71. package/test/data/tree-construction/tests9.dat +0 -457
  72. package/test/data/tree-construction/tests_innerHTML_1.dat +0 -741
  73. package/test/data/tree-construction/tricky01.dat +0 -261
  74. package/test/data/tree-construction/webkit01.dat +0 -594
  75. package/test/data/tree-construction/webkit02.dat +0 -94
  76. package/test/fixtures/formatting_element_list_test.js +0 -267
  77. package/test/fixtures/open_element_stack_test.js +0 -495
  78. package/test/fixtures/parser_test.js +0 -160
  79. package/test/fixtures/tokenizer_test.js +0 -178
  80. package/test/run_tests.js +0 -10
@@ -1,7 +0,0 @@
1
- {"tests": [
2
-
3
- {"description":"<!---- >",
4
- "input":"<!---- >",
5
- "output":["ParseError", "ParseError", ["Comment","-- >"]]}
6
-
7
- ]}
@@ -1,196 +0,0 @@
1
- {"tests": [
2
-
3
- {"description":"Correct Doctype lowercase",
4
- "input":"<!DOCTYPE html>",
5
- "output":[["DOCTYPE", "html", null, null, true]]},
6
-
7
- {"description":"Correct Doctype uppercase",
8
- "input":"<!DOCTYPE HTML>",
9
- "output":[["DOCTYPE", "html", null, null, true]]},
10
-
11
- {"description":"Correct Doctype mixed case",
12
- "input":"<!DOCTYPE HtMl>",
13
- "output":[["DOCTYPE", "html", null, null, true]]},
14
-
15
- {"description":"Correct Doctype case with EOF",
16
- "input":"<!DOCTYPE HtMl",
17
- "output":["ParseError", ["DOCTYPE", "html", null, null, false]]},
18
-
19
- {"description":"Truncated doctype start",
20
- "input":"<!DOC>",
21
- "output":["ParseError", ["Comment", "DOC"]]},
22
-
23
- {"description":"Doctype in error",
24
- "input":"<!DOCTYPE foo>",
25
- "output":[["DOCTYPE", "foo", null, null, true]]},
26
-
27
- {"description":"Single Start Tag",
28
- "input":"<h>",
29
- "output":[["StartTag", "h", {}]]},
30
-
31
- {"description":"Empty end tag",
32
- "input":"</>",
33
- "output":["ParseError"]},
34
-
35
- {"description":"Empty start tag",
36
- "input":"<>",
37
- "output":["ParseError", ["Character", "<>"]]},
38
-
39
- {"description":"Start Tag w/attribute",
40
- "input":"<h a='b'>",
41
- "output":[["StartTag", "h", {"a":"b"}]]},
42
-
43
- {"description":"Start Tag w/attribute no quotes",
44
- "input":"<h a=b>",
45
- "output":[["StartTag", "h", {"a":"b"}]]},
46
-
47
- {"description":"Start/End Tag",
48
- "input":"<h></h>",
49
- "output":[["StartTag", "h", {}], ["EndTag", "h"]]},
50
-
51
- {"description":"Two unclosed start tags",
52
- "input":"<p>One<p>Two",
53
- "output":[["StartTag", "p", {}], ["Character", "One"], ["StartTag", "p", {}], ["Character", "Two"]]},
54
-
55
- {"description":"End Tag w/attribute",
56
- "input":"<h></h a='b'>",
57
- "output":[["StartTag", "h", {}], "ParseError", ["EndTag", "h"]]},
58
-
59
- {"description":"Multiple atts",
60
- "input":"<h a='b' c='d'>",
61
- "output":[["StartTag", "h", {"a":"b", "c":"d"}]]},
62
-
63
- {"description":"Multiple atts no space",
64
- "input":"<h a='b'c='d'>",
65
- "output":["ParseError", ["StartTag", "h", {"a":"b", "c":"d"}]]},
66
-
67
- {"description":"Repeated attr",
68
- "input":"<h a='b' a='d'>",
69
- "output":["ParseError", ["StartTag", "h", {"a":"b"}]]},
70
-
71
- {"description":"Simple comment",
72
- "input":"<!--comment-->",
73
- "output":[["Comment", "comment"]]},
74
-
75
- {"description":"Comment, Central dash no space",
76
- "input":"<!----->",
77
- "output":["ParseError", ["Comment", "-"]]},
78
-
79
- {"description":"Comment, two central dashes",
80
- "input":"<!-- --comment -->",
81
- "output":["ParseError", ["Comment", " --comment "]]},
82
-
83
- {"description":"Unfinished comment",
84
- "input":"<!--comment",
85
- "output":["ParseError", ["Comment", "comment"]]},
86
-
87
- {"description":"Start of a comment",
88
- "input":"<!-",
89
- "output":["ParseError", ["Comment", "-"]]},
90
-
91
- {"description":"Short comment",
92
- "input":"<!-->",
93
- "output":["ParseError", ["Comment", ""]]},
94
-
95
- {"description":"Short comment two",
96
- "input":"<!--->",
97
- "output":["ParseError", ["Comment", ""]]},
98
-
99
- {"description":"Short comment three",
100
- "input":"<!---->",
101
- "output":[["Comment", ""]]},
102
-
103
-
104
- {"description":"Ampersand EOF",
105
- "input":"&",
106
- "output":[["Character", "&"]]},
107
-
108
- {"description":"Ampersand ampersand EOF",
109
- "input":"&&",
110
- "output":[["Character", "&&"]]},
111
-
112
- {"description":"Ampersand space EOF",
113
- "input":"& ",
114
- "output":[["Character", "& "]]},
115
-
116
- {"description":"Unfinished entity",
117
- "input":"&f",
118
- "output":["ParseError", ["Character", "&f"]]},
119
-
120
- {"description":"Ampersand, number sign",
121
- "input":"&#",
122
- "output":["ParseError", ["Character", "&#"]]},
123
-
124
- {"description":"Unfinished numeric entity",
125
- "input":"&#x",
126
- "output":["ParseError", ["Character", "&#x"]]},
127
-
128
- {"description":"Entity with trailing semicolon (1)",
129
- "input":"I'm &not;it",
130
- "output":[["Character","I'm \u00ACit"]]},
131
-
132
- {"description":"Entity with trailing semicolon (2)",
133
- "input":"I'm &notin;",
134
- "output":[["Character","I'm \u2209"]]},
135
-
136
- {"description":"Entity without trailing semicolon (1)",
137
- "input":"I'm &notit",
138
- "output":[["Character","I'm "], "ParseError", ["Character", "\u00ACit"]]},
139
-
140
- {"description":"Entity without trailing semicolon (2)",
141
- "input":"I'm &notin",
142
- "output":[["Character","I'm "], "ParseError", ["Character", "\u00ACin"]]},
143
-
144
- {"description":"Partial entity match at end of file",
145
- "input":"I'm &no",
146
- "output":[["Character","I'm "], "ParseError", ["Character", "&no"]]},
147
-
148
- {"description":"Non-ASCII character reference name",
149
- "input":"&\u00AC;",
150
- "output":["ParseError", ["Character", "&\u00AC;"]]},
151
-
152
- {"description":"ASCII decimal entity",
153
- "input":"&#0036;",
154
- "output":[["Character","$"]]},
155
-
156
- {"description":"ASCII hexadecimal entity",
157
- "input":"&#x3f;",
158
- "output":[["Character","?"]]},
159
-
160
- {"description":"Hexadecimal entity in attribute",
161
- "input":"<h a='&#x3f;'></h>",
162
- "output":[["StartTag", "h", {"a":"?"}], ["EndTag", "h"]]},
163
-
164
- {"description":"Entity in attribute without semicolon ending in x",
165
- "input":"<h a='&notx'>",
166
- "output":["ParseError", ["StartTag", "h", {"a":"&notx"}]]},
167
-
168
- {"description":"Entity in attribute without semicolon ending in 1",
169
- "input":"<h a='&not1'>",
170
- "output":["ParseError", ["StartTag", "h", {"a":"&not1"}]]},
171
-
172
- {"description":"Entity in attribute without semicolon ending in i",
173
- "input":"<h a='&noti'>",
174
- "output":["ParseError", ["StartTag", "h", {"a":"&noti"}]]},
175
-
176
- {"description":"Entity in attribute without semicolon",
177
- "input":"<h a='&COPY'>",
178
- "output":["ParseError", ["StartTag", "h", {"a":"\u00A9"}]]},
179
-
180
- {"description":"Unquoted attribute ending in ampersand",
181
- "input":"<s o=& t>",
182
- "output":[["StartTag","s",{"o":"&","t":""}]]},
183
-
184
- {"description":"Unquoted attribute at end of tag with final character of &, with tag followed by characters",
185
- "input":"<a a=a&>foo",
186
- "output":[["StartTag", "a", {"a":"a&"}], ["Character", "foo"]]},
187
-
188
- {"description":"plaintext element",
189
- "input":"<plaintext>foobar",
190
- "output":[["StartTag","plaintext",{}], ["Character","foobar"]]},
191
-
192
- {"description":"Open angled bracket in unquoted attribute value state",
193
- "input":"<a a=f<>",
194
- "output":["ParseError", ["StartTag", "a", {"a":"f<"}]]}
195
-
196
- ]}
@@ -1,179 +0,0 @@
1
- {"tests": [
2
-
3
- {"description":"DOCTYPE without name",
4
- "input":"<!DOCTYPE>",
5
- "output":["ParseError", "ParseError", ["DOCTYPE", "", null, null, false]]},
6
-
7
- {"description":"DOCTYPE without space before name",
8
- "input":"<!DOCTYPEhtml>",
9
- "output":["ParseError", ["DOCTYPE", "html", null, null, true]]},
10
-
11
- {"description":"Incorrect DOCTYPE without a space before name",
12
- "input":"<!DOCTYPEfoo>",
13
- "output":["ParseError", ["DOCTYPE", "foo", null, null, true]]},
14
-
15
- {"description":"DOCTYPE with publicId",
16
- "input":"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML Transitional 4.01//EN\">",
17
- "output":[["DOCTYPE", "html", "-//W3C//DTD HTML Transitional 4.01//EN", null, true]]},
18
-
19
- {"description":"DOCTYPE with EOF after PUBLIC",
20
- "input":"<!DOCTYPE html PUBLIC",
21
- "output":["ParseError", ["DOCTYPE", "html", null, null, false]]},
22
-
23
- {"description":"DOCTYPE with EOF after PUBLIC '",
24
- "input":"<!DOCTYPE html PUBLIC '",
25
- "output":["ParseError", ["DOCTYPE", "html", "", null, false]]},
26
-
27
- {"description":"DOCTYPE with EOF after PUBLIC 'x",
28
- "input":"<!DOCTYPE html PUBLIC 'x",
29
- "output":["ParseError", ["DOCTYPE", "html", "x", null, false]]},
30
-
31
- {"description":"DOCTYPE with systemId",
32
- "input":"<!DOCTYPE html SYSTEM \"-//W3C//DTD HTML Transitional 4.01//EN\">",
33
- "output":[["DOCTYPE", "html", null, "-//W3C//DTD HTML Transitional 4.01//EN", true]]},
34
-
35
- {"description":"DOCTYPE with publicId and systemId",
36
- "input":"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML Transitional 4.01//EN\" \"-//W3C//DTD HTML Transitional 4.01//EN\">",
37
- "output":[["DOCTYPE", "html", "-//W3C//DTD HTML Transitional 4.01//EN", "-//W3C//DTD HTML Transitional 4.01//EN", true]]},
38
-
39
- {"description":"DOCTYPE with > in double-quoted publicId",
40
- "input":"<!DOCTYPE html PUBLIC \">x",
41
- "output":["ParseError", ["DOCTYPE", "html", "", null, false], ["Character", "x"]]},
42
-
43
- {"description":"DOCTYPE with > in single-quoted publicId",
44
- "input":"<!DOCTYPE html PUBLIC '>x",
45
- "output":["ParseError", ["DOCTYPE", "html", "", null, false], ["Character", "x"]]},
46
-
47
- {"description":"DOCTYPE with > in double-quoted systemId",
48
- "input":"<!DOCTYPE html PUBLIC \"foo\" \">x",
49
- "output":["ParseError", ["DOCTYPE", "html", "foo", "", false], ["Character", "x"]]},
50
-
51
- {"description":"DOCTYPE with > in single-quoted systemId",
52
- "input":"<!DOCTYPE html PUBLIC 'foo' '>x",
53
- "output":["ParseError", ["DOCTYPE", "html", "foo", "", false], ["Character", "x"]]},
54
-
55
- {"description":"Incomplete doctype",
56
- "input":"<!DOCTYPE html ",
57
- "output":["ParseError", ["DOCTYPE", "html", null, null, false]]},
58
-
59
- {"description":"Numeric entity representing the NUL character",
60
- "input":"&#0000;",
61
- "output":["ParseError", ["Character", "\uFFFD"]]},
62
-
63
- {"description":"Hexadecimal entity representing the NUL character",
64
- "input":"&#x0000;",
65
- "output":["ParseError", ["Character", "\uFFFD"]]},
66
-
67
- {"description":"Numeric entity representing a codepoint after 1114111 (U+10FFFF)",
68
- "input":"&#2225222;",
69
- "output":["ParseError", ["Character", "\uFFFD"]]},
70
-
71
- {"description":"Hexadecimal entity representing a codepoint after 1114111 (U+10FFFF)",
72
- "input":"&#x1010FFFF;",
73
- "output":["ParseError", ["Character", "\uFFFD"]]},
74
-
75
- {"description":"Hexadecimal entity pair representing a surrogate pair",
76
- "input":"&#xD869;&#xDED6;",
77
- "output":["ParseError", ["Character", "\uFFFD"], "ParseError", ["Character", "\uFFFD"]]},
78
-
79
- {"description":"Hexadecimal entity with mixed uppercase and lowercase",
80
- "input":"&#xaBcD;",
81
- "output":[["Character", "\uABCD"]]},
82
-
83
- {"description":"Entity without a name",
84
- "input":"&;",
85
- "output":["ParseError", ["Character", "&;"]]},
86
-
87
- {"description":"Unescaped ampersand in attribute value",
88
- "input":"<h a='&'>",
89
- "output":[["StartTag", "h", { "a":"&" }]]},
90
-
91
- {"description":"StartTag containing <",
92
- "input":"<a<b>",
93
- "output":[["StartTag", "a<b", { }]]},
94
-
95
- {"description":"Non-void element containing trailing /",
96
- "input":"<h/>",
97
- "output":[["StartTag","h",{},true]]},
98
-
99
- {"description":"Void element with permitted slash",
100
- "input":"<br/>",
101
- "output":[["StartTag","br",{},true]]},
102
-
103
- {"description":"Void element with permitted slash (with attribute)",
104
- "input":"<br foo='bar'/>",
105
- "output":[["StartTag","br",{"foo":"bar"},true]]},
106
-
107
- {"description":"StartTag containing /",
108
- "input":"<h/a='b'>",
109
- "output":["ParseError", ["StartTag", "h", { "a":"b" }]]},
110
-
111
- {"description":"Double-quoted attribute value",
112
- "input":"<h a=\"b\">",
113
- "output":[["StartTag", "h", { "a":"b" }]]},
114
-
115
- {"description":"Unescaped </",
116
- "input":"</",
117
- "output":["ParseError", ["Character", "</"]]},
118
-
119
- {"description":"Illegal end tag name",
120
- "input":"</1>",
121
- "output":["ParseError", ["Comment", "1"]]},
122
-
123
- {"description":"Simili processing instruction",
124
- "input":"<?namespace>",
125
- "output":["ParseError", ["Comment", "?namespace"]]},
126
-
127
- {"description":"A bogus comment stops at >, even if preceeded by two dashes",
128
- "input":"<?foo-->",
129
- "output":["ParseError", ["Comment", "?foo--"]]},
130
-
131
- {"description":"Unescaped <",
132
- "input":"foo < bar",
133
- "output":[["Character", "foo "], "ParseError", ["Character", "< bar"]]},
134
-
135
- {"description":"Null Byte Replacement",
136
- "input":"\u0000",
137
- "output":["ParseError", ["Character", "\u0000"]]},
138
-
139
- {"description":"Comment with dash",
140
- "input":"<!---x",
141
- "output":["ParseError", ["Comment", "-x"]]},
142
-
143
- {"description":"Entity + newline",
144
- "input":"\nx\n&gt;\n",
145
- "output":[["Character","\nx\n>\n"]]},
146
-
147
- {"description":"Start tag with no attributes but space before the greater-than sign",
148
- "input":"<h >",
149
- "output":[["StartTag", "h", {}]]},
150
-
151
- {"description":"Empty attribute followed by uppercase attribute",
152
- "input":"<h a B=''>",
153
- "output":[["StartTag", "h", {"a":"", "b":""}]]},
154
-
155
- {"description":"Double-quote after attribute name",
156
- "input":"<h a \">",
157
- "output":["ParseError", ["StartTag", "h", {"a":"", "\"":""}]]},
158
-
159
- {"description":"Single-quote after attribute name",
160
- "input":"<h a '>",
161
- "output":["ParseError", ["StartTag", "h", {"a":"", "'":""}]]},
162
-
163
- {"description":"Empty end tag with following characters",
164
- "input":"a</>bc",
165
- "output":[["Character", "a"], "ParseError", ["Character", "bc"]]},
166
-
167
- {"description":"Empty end tag with following tag",
168
- "input":"a</><b>c",
169
- "output":[["Character", "a"], "ParseError", ["StartTag", "b", {}], ["Character", "c"]]},
170
-
171
- {"description":"Empty end tag with following comment",
172
- "input":"a</><!--b-->c",
173
- "output":[["Character", "a"], "ParseError", ["Comment", "b"], ["Character", "c"]]},
174
-
175
- {"description":"Empty end tag with following end tag",
176
- "input":"a</></b>c",
177
- "output":[["Character", "a"], "ParseError", ["EndTag", "b"], ["Character", "c"]]}
178
-
179
- ]}