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,267 +0,0 @@
1
- var html = require('../../lib/html'),
2
- FormattingElementList = require('../../lib/formatting_element_list').FormattingElementList,
3
- defaultTreeAdapter = require('../../lib/default_tree_adapter');
4
-
5
- //Aliases
6
- var $ = html.TAG_NAMES,
7
- NS = html.NAMESPACES;
8
-
9
- exports['Insert marker'] = function (t) {
10
- var list = new FormattingElementList(defaultTreeAdapter);
11
-
12
- list.insertMarker();
13
- t.strictEqual(list.length, 1);
14
- t.strictEqual(list.entries[0].type, FormattingElementList.MARKER_ENTRY);
15
-
16
- list.insertMarker();
17
- t.strictEqual(list.length, 2);
18
- t.strictEqual(list.entries[1].type, FormattingElementList.MARKER_ENTRY);
19
-
20
- t.done();
21
- };
22
-
23
- exports['Push element'] = function (t) {
24
- var list = new FormattingElementList(defaultTreeAdapter),
25
- element1Token = 'token1',
26
- element2Token = 'token2',
27
- element1 = {
28
- tagName: $.DIV,
29
- namespaceURI: NS.HTML,
30
- attrs: []
31
- },
32
- element2 = {
33
- tagName: $.P,
34
- namespaceURI: NS.HTML,
35
- attrs: []
36
- };
37
-
38
- list.pushElement(element1, element1Token);
39
- t.strictEqual(list.length, 1);
40
- t.strictEqual(list.entries[0].type, FormattingElementList.ELEMENT_ENTRY);
41
- t.strictEqual(list.entries[0].element, element1);
42
- t.strictEqual(list.entries[0].token, element1Token);
43
-
44
- list.pushElement(element2, element2Token);
45
- t.strictEqual(list.length, 2);
46
- t.strictEqual(list.entries[1].type, FormattingElementList.ELEMENT_ENTRY);
47
- t.strictEqual(list.entries[1].element, element2);
48
- t.strictEqual(list.entries[1].token, element2Token);
49
-
50
- t.done();
51
- };
52
-
53
- exports['Insert element after bookmark'] = function (t) {
54
- var list = new FormattingElementList(defaultTreeAdapter),
55
- token = 'token1',
56
- element1 = {
57
- tagName: $.DIV,
58
- namespaceURI: NS.HTML,
59
- attrs: []
60
- },
61
- element2 = {
62
- tagName: $.P,
63
- namespaceURI: NS.HTML,
64
- attrs: []
65
- },
66
- element3 = {
67
- tagName: $.SPAN,
68
- namespaceURI: NS.HTML,
69
- attrs: []
70
- },
71
- element4 = {
72
- tagName: $.TITLE,
73
- namespaceURI: NS.HTML,
74
- attrs: []
75
- };
76
-
77
- list.pushElement(element1, token);
78
- list.bookmark = list.entries[0];
79
-
80
- list.pushElement(element2, token);
81
- list.pushElement(element3, token);
82
-
83
- list.insertElementAfterBookmark(element4, token);
84
-
85
- t.strictEqual(list.length, 4);
86
- t.strictEqual(list.entries[1].element, element4);
87
-
88
- t.done();
89
- };
90
-
91
- exports['Push element - Noah Ark condition'] = function (t) {
92
- var list = new FormattingElementList(defaultTreeAdapter),
93
- token1 = 'token1',
94
- token2 = 'token2',
95
- token3 = 'token3',
96
- token4 = 'token4',
97
- token5 = 'token5',
98
- token6 = 'token6',
99
- element1 = {
100
- tagName: $.DIV,
101
- namespaceURI: NS.HTML,
102
- attrs: [
103
- {name: 'attr1', value: 'val1'},
104
- {name: 'attr2', value: 'val2'}
105
- ]
106
- },
107
- element2 = {
108
- tagName: $.DIV,
109
- namespaceURI: NS.HTML,
110
- attrs: [
111
- {name: 'attr1', value: 'val1'},
112
- {name: 'attr2', value: 'someOtherValue'}
113
- ]
114
- };
115
-
116
- list.pushElement(element1, token1);
117
- list.pushElement(element1, token2);
118
- list.pushElement(element2, token3);
119
- list.pushElement(element1, token4);
120
-
121
- t.strictEqual(list.length, 4);
122
- t.strictEqual(list.entries[0].token, token1);
123
- t.strictEqual(list.entries[1].token, token2);
124
- t.strictEqual(list.entries[2].token, token3);
125
- t.strictEqual(list.entries[3].token, token4);
126
-
127
- list.pushElement(element1, token5);
128
-
129
- t.strictEqual(list.length, 4);
130
- t.strictEqual(list.entries[0].token, token2);
131
- t.strictEqual(list.entries[1].token, token3);
132
- t.strictEqual(list.entries[2].token, token4);
133
- t.strictEqual(list.entries[3].token, token5);
134
-
135
- list.insertMarker();
136
- list.pushElement(element1, token6);
137
-
138
- t.strictEqual(list.length, 6);
139
- t.strictEqual(list.entries[0].token, token2);
140
- t.strictEqual(list.entries[1].token, token3);
141
- t.strictEqual(list.entries[2].token, token4);
142
- t.strictEqual(list.entries[3].token, token5);
143
- t.strictEqual(list.entries[4].type, FormattingElementList.MARKER_ENTRY);
144
- t.strictEqual(list.entries[5].token, token6);
145
-
146
- t.done();
147
- };
148
-
149
- exports['Clear to the last marker'] = function (t) {
150
- var list = new FormattingElementList(defaultTreeAdapter),
151
- token = 'token',
152
- element1 = {
153
- tagName: $.DIV,
154
- namespaceURI: NS.HTML,
155
- attrs: [
156
- {name: 'attr1', value: 'val1'},
157
- {name: 'attr2', value: 'val2'}
158
- ]
159
- },
160
- element2 = {
161
- tagName: $.DIV,
162
- namespaceURI: NS.HTML,
163
- attrs: [
164
- {name: 'attr1', value: 'val1'},
165
- {name: 'attr2', value: 'someOtherValue'}
166
- ]
167
- };
168
-
169
- list.pushElement(element1, token);
170
- list.pushElement(element2, token);
171
- list.insertMarker();
172
- list.pushElement(element1, token);
173
- list.pushElement(element1, token);
174
- list.pushElement(element2, token);
175
-
176
- list.clearToLastMarker();
177
-
178
- t.strictEqual(list.length, 2);
179
-
180
- t.done();
181
- };
182
-
183
- exports['Remove entry'] = function (t) {
184
- var list = new FormattingElementList(defaultTreeAdapter),
185
- token = 'token',
186
- element1 = {
187
- tagName: $.DIV,
188
- namespaceURI: NS.HTML,
189
- attrs: [
190
- {name: 'attr1', value: 'val1'},
191
- {name: 'attr2', value: 'val2'}
192
- ]
193
- },
194
- element2 = {
195
- tagName: $.DIV,
196
- namespaceURI: NS.HTML,
197
- attrs: [
198
- {name: 'attr1', value: 'val1'},
199
- {name: 'attr2', value: 'someOtherValue'}
200
- ]
201
- };
202
-
203
- list.pushElement(element1, token);
204
- list.pushElement(element2, token);
205
- list.pushElement(element2, token);
206
-
207
- list.removeEntry(list.entries[0]);
208
-
209
- t.strictEqual(list.length, 2);
210
-
211
- for (var i = list.length - 1; i >= 0; i--)
212
- t.notStrictEqual(list.entries[i].element, element1);
213
-
214
- t.done();
215
- };
216
-
217
- exports['Get entry in scope with given tag name'] = function (t) {
218
- var list = new FormattingElementList(defaultTreeAdapter),
219
- token = 'token',
220
- element = {
221
- tagName: $.DIV,
222
- namespaceURI: NS.HTML,
223
- attrs: []
224
- };
225
-
226
- t.ok(!list.getElementEntryInScopeWithTagName($.DIV));
227
-
228
- list.pushElement(element, token);
229
- list.pushElement(element, token);
230
- t.strictEqual(list.getElementEntryInScopeWithTagName($.DIV), list.entries[1]);
231
-
232
- list.insertMarker();
233
- t.ok(!list.getElementEntryInScopeWithTagName($.DIV));
234
-
235
- list.pushElement(element, token);
236
- t.strictEqual(list.getElementEntryInScopeWithTagName($.DIV), list.entries[3]);
237
-
238
- t.done();
239
- };
240
-
241
- exports['Get element entry'] = function (t) {
242
- var list = new FormattingElementList(defaultTreeAdapter),
243
- token = 'token',
244
- element1 = {
245
- tagName: $.DIV,
246
- namespaceURI: NS.HTML,
247
- attrs: []
248
- },
249
- element2 = {
250
- tagName: $.A,
251
- namespaceURI: NS.HTML,
252
- attrs: []
253
- };
254
-
255
-
256
- list.pushElement(element2, token);
257
- list.pushElement(element1, token);
258
- list.pushElement(element2, token);
259
- list.insertMarker();
260
-
261
- var entry = list.getElementEntry(element1);
262
- t.strictEqual(entry.type, FormattingElementList.ELEMENT_ENTRY);
263
- t.strictEqual(entry.token, token);
264
- t.strictEqual(entry.element, element1);
265
-
266
- t.done();
267
- };