parse5 1.0.1 → 1.1.3

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.
@@ -1,380 +1,21 @@
1
- var Tokenizer = require('../tokenization_stage/tokenizer'),
1
+ var Tokenizer = require('../tokenization/tokenizer'),
2
2
  OpenElementStack = require('./open_element_stack'),
3
3
  FormattingElementList = require('./formatting_element_list'),
4
- defaultTreeAdapter = require('../tree_adapters/default'),
5
- UNICODE = require('../const/unicode'),
6
- HTML = require('../const/html');
4
+ Doctype = require('./doctype'),
5
+ DefaultTreeAdapter = require('../tree_adapters/default'),
6
+ ForeignContent = require('../common/foreign_content'),
7
+ UNICODE = require('../common/unicode'),
8
+ HTML = require('../common/html');
7
9
 
8
10
  //Aliases
9
11
  var $ = HTML.TAG_NAMES,
10
- NS = HTML.NAMESPACES;
12
+ NS = HTML.NAMESPACES,
13
+ ATTRS = HTML.ATTRS;
11
14
 
12
15
  //Misc constants
13
16
  var SEARCHABLE_INDEX_DEFAULT_PROMPT = 'This is a searchable index. Enter search keywords: ',
14
- HIDDEN_INPUT_TYPE = 'hidden',
15
17
  SEARCHABLE_INDEX_INPUT_NAME = 'isindex',
16
- TEXT_HTML_MIME_TYPE = 'text/html',
17
- APPLICATION_XML_MIME_TYPE = 'application/xhtml+xml';
18
-
19
- //Attributes
20
- var TYPE_ATTR = 'type',
21
- ACTION_ATTR = 'action',
22
- ENCODING_ATTR = 'encoding',
23
- PROMPT_ATTR = 'prompt',
24
- NAME_ATTR = 'name',
25
- COLOR_ATTR = 'color',
26
- FACE_ATTR = 'face',
27
- SIZE_ATTR = 'size',
28
- DEFINITION_URL_ATTR = 'definitionurl',
29
- ADJUSTED_DEFINITION_URL_ATTR = 'definitionURL',
30
- SVG_ATTRS_ADJUSTMENT_MAP = {
31
- 'attributename': 'attributeName',
32
- 'attributetype': 'attributeType',
33
- 'basefrequency': 'baseFrequency',
34
- 'baseprofile': 'baseProfile',
35
- 'calcmode': 'calcMode',
36
- 'clippathunits': 'clipPathUnits',
37
- 'contentscripttype': 'contentScriptType',
38
- 'contentstyletype': 'contentStyleType',
39
- 'diffuseconstant': 'diffuseConstant',
40
- 'edgemode': 'edgeMode',
41
- 'externalresourcesrequired': 'externalResourcesRequired',
42
- 'filterres': 'filterRes',
43
- 'filterunits': 'filterUnits',
44
- 'glyphref': 'glyphRef',
45
- 'gradienttransform': 'gradientTransform',
46
- 'gradientunits': 'gradientUnits',
47
- 'kernelmatrix': 'kernelMatrix',
48
- 'kernelunitlength': 'kernelUnitLength',
49
- 'keypoints': 'keyPoints',
50
- 'keysplines': 'keySplines',
51
- 'keytimes': 'keyTimes',
52
- 'lengthadjust': 'lengthAdjust',
53
- 'limitingconeangle': 'limitingConeAngle',
54
- 'markerheight': 'markerHeight',
55
- 'markerunits': 'markerUnits',
56
- 'markerwidth': 'markerWidth',
57
- 'maskcontentunits': 'maskContentUnits',
58
- 'maskunits': 'maskUnits',
59
- 'numoctaves': 'numOctaves',
60
- 'pathlength': 'pathLength',
61
- 'patterncontentunits': 'patternContentUnits',
62
- 'patterntransform': 'patternTransform',
63
- 'patternunits': 'patternUnits',
64
- 'pointsatx': 'pointsAtX',
65
- 'pointsaty': 'pointsAtY',
66
- 'pointsatz': 'pointsAtZ',
67
- 'preservealpha': 'preserveAlpha',
68
- 'preserveaspectratio': 'preserveAspectRatio',
69
- 'primitiveunits': 'primitiveUnits',
70
- 'refx': 'refX',
71
- 'refy': 'refY',
72
- 'repeatcount': 'repeatCount',
73
- 'repeatdur': 'repeatDur',
74
- 'requiredextensions': 'requiredExtensions',
75
- 'requiredfeatures': 'requiredFeatures',
76
- 'specularconstant': 'specularConstant',
77
- 'specularexponent': 'specularExponent',
78
- 'spreadmethod': 'spreadMethod',
79
- 'startoffset': 'startOffset',
80
- 'stddeviation': 'stdDeviation',
81
- 'stitchtiles': 'stitchTiles',
82
- 'surfacescale': 'surfaceScale',
83
- 'systemlanguage': 'systemLanguage',
84
- 'tablevalues': 'tableValues',
85
- 'targetx': 'targetX',
86
- 'targety': 'targetY',
87
- 'textlength': 'textLength',
88
- 'viewbox': 'viewBox',
89
- 'viewtarget': 'viewTarget',
90
- 'xchannelselector': 'xChannelSelector',
91
- 'ychannelselector': 'yChannelSelector',
92
- 'zoomandpan': 'zoomAndPan'
93
- },
94
- FOREIGN_ATTRS_ADJUSTMENT_MAP = {
95
- 'xlink:actuate': {prefix: 'xlink', name: 'actuate', namespace: NS.XLINK},
96
- 'xlink:arcrole': {prefix: 'xlink', name: 'arcrole', namespace: NS.XLINK},
97
- 'xlink:href': {prefix: 'xlink', name: 'href', namespace: NS.XLINK},
98
- 'xlink:role': {prefix: 'xlink', name: 'role', namespace: NS.XLINK},
99
- 'xlink:show': {prefix: 'xlink', name: 'show', namespace: NS.XLINK},
100
- 'xlink:title': {prefix: 'xlink', name: 'title', namespace: NS.XLINK},
101
- 'xlink:type': {prefix: 'xlink', name: 'type', namespace: NS.XLINK},
102
- 'xml:base': {prefix: 'xml', name: 'base', namespace: NS.XML},
103
- 'xml:lang': {prefix: 'xml', name: 'lang', namespace: NS.XML},
104
- 'xml:space': {prefix: 'xml', name: 'space', namespace: NS.XML},
105
- 'xmlns': {prefix: '', name: 'xmlns', namespace: NS.XMLNS},
106
- 'xmlns:xlink': {prefix: 'xmlns', name: 'xlink', namespace: NS.XMLNS}
107
-
108
- };
109
-
110
- //SVG tag names adjustment map
111
- var SVG_TAG_NAMES_ADJUSTMENT_MAP = {
112
- 'altglyph': 'altGlyph',
113
- 'altglyphdef': 'altGlyphDef',
114
- 'altglyphitem': 'altGlyphItem',
115
- 'animatecolor': 'animateColor',
116
- 'animatemotion': 'animateMotion',
117
- 'animatetransform': 'animateTransform',
118
- 'clippath': 'clipPath',
119
- 'feblend': 'feBlend',
120
- 'fecolormatrix': 'feColorMatrix',
121
- 'fecomponenttransfer': 'feComponentTransfer',
122
- 'fecomposite': 'feComposite',
123
- 'feconvolvematrix': 'feConvolveMatrix',
124
- 'fediffuselighting': 'feDiffuseLighting',
125
- 'fedisplacementmap': 'feDisplacementMap',
126
- 'fedistantlight': 'feDistantLight',
127
- 'feflood': 'feFlood',
128
- 'fefunca': 'feFuncA',
129
- 'fefuncb': 'feFuncB',
130
- 'fefuncg': 'feFuncG',
131
- 'fefuncr': 'feFuncR',
132
- 'fegaussianblur': 'feGaussianBlur',
133
- 'feimage': 'feImage',
134
- 'femerge': 'feMerge',
135
- 'femergenode': 'feMergeNode',
136
- 'femorphology': 'feMorphology',
137
- 'feoffset': 'feOffset',
138
- 'fepointlight': 'fePointLight',
139
- 'fespecularlighting': 'feSpecularLighting',
140
- 'fespotlight': 'feSpotLight',
141
- 'fetile': 'feTile',
142
- 'feturbulence': 'feTurbulence',
143
- 'foreignobject': 'foreignObject',
144
- 'glyphref': 'glyphRef',
145
- 'lineargradient': 'linearGradient',
146
- 'radialgradient': 'radialGradient',
147
- 'textpath': 'textPath'
148
- };
149
-
150
- //Tags that are not allowed in foreign content
151
- var NOT_ALLOWED_IN_FOREIGN_CONTENT = {};
152
-
153
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.B] = true;
154
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.BIG] = true;
155
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.BLOCKQUOTE] = true;
156
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.BODY] = true;
157
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.BR] = true;
158
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.CENTER] = true;
159
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.CODE] = true;
160
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.DD] = true;
161
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.DIV] = true;
162
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.DL] = true;
163
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.DT] = true;
164
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.EM] = true;
165
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.EMBED] = true;
166
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.H1] = true;
167
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.H2] = true;
168
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.H3] = true;
169
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.H4] = true;
170
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.H5] = true;
171
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.H6] = true;
172
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.HEAD] = true;
173
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.HR] = true;
174
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.I] = true;
175
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.IMG] = true;
176
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.LI] = true;
177
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.LISTING] = true;
178
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.MENU] = true;
179
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.META] = true;
180
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.NOBR] = true;
181
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.OL] = true;
182
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.P] = true;
183
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.PRE] = true;
184
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.RUBY] = true;
185
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.S] = true;
186
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.SMALL] = true;
187
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.SPAN] = true;
188
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.STRONG] = true;
189
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.STRIKE] = true;
190
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.SUB] = true;
191
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.SUP] = true;
192
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.TABLE] = true;
193
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.TT] = true;
194
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.U] = true;
195
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.UL] = true;
196
- NOT_ALLOWED_IN_FOREIGN_CONTENT[$.VAR] = true;
197
-
198
- //Special elements
199
- var SPECIAL_ELEMENTS = {};
200
-
201
- SPECIAL_ELEMENTS[NS.HTML] = {};
202
- SPECIAL_ELEMENTS[NS.HTML][$.ADDRESS] = true;
203
- SPECIAL_ELEMENTS[NS.HTML][$.APPLET] = true;
204
- SPECIAL_ELEMENTS[NS.HTML][$.AREA] = true;
205
- SPECIAL_ELEMENTS[NS.HTML][$.ARTICLE] = true;
206
- SPECIAL_ELEMENTS[NS.HTML][$.ASIDE] = true;
207
- SPECIAL_ELEMENTS[NS.HTML][$.BASE] = true;
208
- SPECIAL_ELEMENTS[NS.HTML][$.BASEFONT] = true;
209
- SPECIAL_ELEMENTS[NS.HTML][$.BGSOUND] = true;
210
- SPECIAL_ELEMENTS[NS.HTML][$.BLOCKQUOTE] = true;
211
- SPECIAL_ELEMENTS[NS.HTML][$.BODY] = true;
212
- SPECIAL_ELEMENTS[NS.HTML][$.BR] = true;
213
- SPECIAL_ELEMENTS[NS.HTML][$.BUTTON] = true;
214
- SPECIAL_ELEMENTS[NS.HTML][$.CAPTION] = true;
215
- SPECIAL_ELEMENTS[NS.HTML][$.CENTER] = true;
216
- SPECIAL_ELEMENTS[NS.HTML][$.COL] = true;
217
- SPECIAL_ELEMENTS[NS.HTML][$.COLGROUP] = true;
218
- SPECIAL_ELEMENTS[NS.HTML][$.DD] = true;
219
- SPECIAL_ELEMENTS[NS.HTML][$.DETAILS] = true;
220
- SPECIAL_ELEMENTS[NS.HTML][$.DIR] = true;
221
- SPECIAL_ELEMENTS[NS.HTML][$.DIV] = true;
222
- SPECIAL_ELEMENTS[NS.HTML][$.DL] = true;
223
- SPECIAL_ELEMENTS[NS.HTML][$.DT] = true;
224
- SPECIAL_ELEMENTS[NS.HTML][$.EMBED] = true;
225
- SPECIAL_ELEMENTS[NS.HTML][$.FIELDSET] = true;
226
- SPECIAL_ELEMENTS[NS.HTML][$.FIGCAPTION] = true;
227
- SPECIAL_ELEMENTS[NS.HTML][$.FIGURE] = true;
228
- SPECIAL_ELEMENTS[NS.HTML][$.FOOTER] = true;
229
- SPECIAL_ELEMENTS[NS.HTML][$.FORM] = true;
230
- SPECIAL_ELEMENTS[NS.HTML][$.FRAME] = true;
231
- SPECIAL_ELEMENTS[NS.HTML][$.FRAMESET] = true;
232
- SPECIAL_ELEMENTS[NS.HTML][$.H1] = true;
233
- SPECIAL_ELEMENTS[NS.HTML][$.H2] = true;
234
- SPECIAL_ELEMENTS[NS.HTML][$.H3] = true;
235
- SPECIAL_ELEMENTS[NS.HTML][$.H4] = true;
236
- SPECIAL_ELEMENTS[NS.HTML][$.H5] = true;
237
- SPECIAL_ELEMENTS[NS.HTML][$.H6] = true;
238
- SPECIAL_ELEMENTS[NS.HTML][$.HEAD] = true;
239
- SPECIAL_ELEMENTS[NS.HTML][$.HEADER] = true;
240
- SPECIAL_ELEMENTS[NS.HTML][$.HGROUP] = true;
241
- SPECIAL_ELEMENTS[NS.HTML][$.HR] = true;
242
- SPECIAL_ELEMENTS[NS.HTML][$.HTML] = true;
243
- SPECIAL_ELEMENTS[NS.HTML][$.IFRAME] = true;
244
- SPECIAL_ELEMENTS[NS.HTML][$.IMG] = true;
245
- SPECIAL_ELEMENTS[NS.HTML][$.INPUT] = true;
246
- SPECIAL_ELEMENTS[NS.HTML][$.ISINDEX] = true;
247
- SPECIAL_ELEMENTS[NS.HTML][$.LI] = true;
248
- SPECIAL_ELEMENTS[NS.HTML][$.LINK] = true;
249
- SPECIAL_ELEMENTS[NS.HTML][$.LISTING] = true;
250
- SPECIAL_ELEMENTS[NS.HTML][$.MAIN] = true;
251
- SPECIAL_ELEMENTS[NS.HTML][$.MARQUEE] = true;
252
- SPECIAL_ELEMENTS[NS.HTML][$.MENU] = true;
253
- SPECIAL_ELEMENTS[NS.HTML][$.MENUITEM] = true;
254
- SPECIAL_ELEMENTS[NS.HTML][$.META] = true;
255
- SPECIAL_ELEMENTS[NS.HTML][$.NAV] = true;
256
- SPECIAL_ELEMENTS[NS.HTML][$.NOEMBED] = true;
257
- SPECIAL_ELEMENTS[NS.HTML][$.NOFRAMES] = true;
258
- SPECIAL_ELEMENTS[NS.HTML][$.NOSCRIPT] = true;
259
- SPECIAL_ELEMENTS[NS.HTML][$.OBJECT] = true;
260
- SPECIAL_ELEMENTS[NS.HTML][$.OL] = true;
261
- SPECIAL_ELEMENTS[NS.HTML][$.P] = true;
262
- SPECIAL_ELEMENTS[NS.HTML][$.PARAM] = true;
263
- SPECIAL_ELEMENTS[NS.HTML][$.PLAINTEXT] = true;
264
- SPECIAL_ELEMENTS[NS.HTML][$.PRE] = true;
265
- SPECIAL_ELEMENTS[NS.HTML][$.SCRIPT] = true;
266
- SPECIAL_ELEMENTS[NS.HTML][$.SECTION] = true;
267
- SPECIAL_ELEMENTS[NS.HTML][$.SELECT] = true;
268
- SPECIAL_ELEMENTS[NS.HTML][$.SOURCE] = true;
269
- SPECIAL_ELEMENTS[NS.HTML][$.STYLE] = true;
270
- SPECIAL_ELEMENTS[NS.HTML][$.SUMMARY] = true;
271
- SPECIAL_ELEMENTS[NS.HTML][$.TABLE] = true;
272
- SPECIAL_ELEMENTS[NS.HTML][$.TBODY] = true;
273
- SPECIAL_ELEMENTS[NS.HTML][$.TD] = true;
274
- SPECIAL_ELEMENTS[NS.HTML][$.TEXTAREA] = true;
275
- SPECIAL_ELEMENTS[NS.HTML][$.TFOOT] = true;
276
- SPECIAL_ELEMENTS[NS.HTML][$.TH] = true;
277
- SPECIAL_ELEMENTS[NS.HTML][$.THEAD] = true;
278
- SPECIAL_ELEMENTS[NS.HTML][$.TITLE] = true;
279
- SPECIAL_ELEMENTS[NS.HTML][$.TR] = true;
280
- SPECIAL_ELEMENTS[NS.HTML][$.TRACK] = true;
281
- SPECIAL_ELEMENTS[NS.HTML][$.UL] = true;
282
- SPECIAL_ELEMENTS[NS.HTML][$.WBR] = true;
283
- SPECIAL_ELEMENTS[NS.HTML][$.XMP] = true;
284
-
285
- SPECIAL_ELEMENTS[NS.MATHML] = {};
286
- SPECIAL_ELEMENTS[NS.MATHML][$.MI] = true;
287
- SPECIAL_ELEMENTS[NS.MATHML][$.MO] = true;
288
- SPECIAL_ELEMENTS[NS.MATHML][$.MN] = true;
289
- SPECIAL_ELEMENTS[NS.MATHML][$.MS] = true;
290
- SPECIAL_ELEMENTS[NS.MATHML][$.MTEXT] = true;
291
- SPECIAL_ELEMENTS[NS.MATHML][$.ANNOTATION_XML] = true;
292
-
293
- SPECIAL_ELEMENTS[NS.SVG] = {};
294
- SPECIAL_ELEMENTS[NS.SVG][$.TITLE] = true;
295
- SPECIAL_ELEMENTS[NS.SVG][$.FOREIGN_OBJECT] = true;
296
- SPECIAL_ELEMENTS[NS.SVG][$.DESC] = true;
297
-
298
- //Doctype
299
- var VALID_DOCTYPE_NAME = 'html',
300
- QUIRKS_MODE_SYSTEM_ID = 'http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd',
301
- QUIRKS_MODE_PUBLIC_ID_PREFIXES = [
302
- "+//silmaril//dtd html pro v0r11 19970101//en",
303
- "-//advasoft ltd//dtd html 3.0 aswedit + extensions//en",
304
- "-//as//dtd html 3.0 aswedit + extensions//en",
305
- "-//ietf//dtd html 2.0 level 1//en",
306
- "-//ietf//dtd html 2.0 level 2//en",
307
- "-//ietf//dtd html 2.0 strict level 1//en",
308
- "-//ietf//dtd html 2.0 strict level 2//en",
309
- "-//ietf//dtd html 2.0 strict//en",
310
- "-//ietf//dtd html 2.0//en",
311
- "-//ietf//dtd html 2.1e//en",
312
- "-//ietf//dtd html 3.0//en",
313
- "-//ietf//dtd html 3.0//en//",
314
- "-//ietf//dtd html 3.2 final//en",
315
- "-//ietf//dtd html 3.2//en",
316
- "-//ietf//dtd html 3//en",
317
- "-//ietf//dtd html level 0//en",
318
- "-//ietf//dtd html level 0//en//2.0",
319
- "-//ietf//dtd html level 1//en",
320
- "-//ietf//dtd html level 1//en//2.0",
321
- "-//ietf//dtd html level 2//en",
322
- "-//ietf//dtd html level 2//en//2.0",
323
- "-//ietf//dtd html level 3//en",
324
- "-//ietf//dtd html level 3//en//3.0",
325
- "-//ietf//dtd html strict level 0//en",
326
- "-//ietf//dtd html strict level 0//en//2.0",
327
- "-//ietf//dtd html strict level 1//en",
328
- "-//ietf//dtd html strict level 1//en//2.0",
329
- "-//ietf//dtd html strict level 2//en",
330
- "-//ietf//dtd html strict level 2//en//2.0",
331
- "-//ietf//dtd html strict level 3//en",
332
- "-//ietf//dtd html strict level 3//en//3.0",
333
- "-//ietf//dtd html strict//en",
334
- "-//ietf//dtd html strict//en//2.0",
335
- "-//ietf//dtd html strict//en//3.0",
336
- "-//ietf//dtd html//en",
337
- "-//ietf//dtd html//en//2.0",
338
- "-//ietf//dtd html//en//3.0",
339
- "-//metrius//dtd metrius presentational//en",
340
- "-//microsoft//dtd internet explorer 2.0 html strict//en",
341
- "-//microsoft//dtd internet explorer 2.0 html//en",
342
- "-//microsoft//dtd internet explorer 2.0 tables//en",
343
- "-//microsoft//dtd internet explorer 3.0 html strict//en",
344
- "-//microsoft//dtd internet explorer 3.0 html//en",
345
- "-//microsoft//dtd internet explorer 3.0 tables//en",
346
- "-//netscape comm. corp.//dtd html//en",
347
- "-//netscape comm. corp.//dtd strict html//en",
348
- "-//o'reilly and associates//dtd html 2.0//en",
349
- "-//o'reilly and associates//dtd html extended 1.0//en",
350
- "-//spyglass//dtd html 2.0 extended//en",
351
- "-//sq//dtd html 2.0 hotmetal + extensions//en",
352
- "-//sun microsystems corp.//dtd hotjava html//en",
353
- "-//sun microsystems corp.//dtd hotjava strict html//en",
354
- "-//w3c//dtd html 3 1995-03-24//en",
355
- "-//w3c//dtd html 3.2 draft//en",
356
- "-//w3c//dtd html 3.2 final//en",
357
- "-//w3c//dtd html 3.2//en",
358
- "-//w3c//dtd html 3.2s draft//en",
359
- "-//w3c//dtd html 4.0 frameset//en",
360
- "-//w3c//dtd html 4.0 transitional//en",
361
- "-//w3c//dtd html experimental 19960712//en",
362
- "-//w3c//dtd html experimental 970421//en",
363
- "-//w3c//dtd w3 html//en",
364
- "-//w3o//dtd w3 html 3.0//en",
365
- "-//w3o//dtd w3 html 3.0//en//",
366
- "-//webtechs//dtd mozilla html 2.0//en",
367
- "-//webtechs//dtd mozilla html//en"
368
- ],
369
- QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES = [
370
- '-//w3c//dtd html 4.01 frameset//',
371
- '-//w3c//dtd html 4.01 transitional//'
372
- ],
373
- QUIRKS_MODE_PUBLIC_IDS = [
374
- '-//w3o//dtd w3 html strict 3.0//en//',
375
- '-/w3c/dtd html 4.0 transitional/en',
376
- 'html'
377
- ];
18
+ HIDDEN_INPUT_TYPE = 'hidden';
378
19
 
379
20
  //Insertion modes
380
21
  var INITIAL_MODE = 'INITIAL_MODE',
@@ -628,102 +269,14 @@ _[AFTER_AFTER_FRAMESET_MODE][Tokenizer.START_TAG_TOKEN] = startTagAfterAfterFram
628
269
  _[AFTER_AFTER_FRAMESET_MODE][Tokenizer.END_TAG_TOKEN] = ignoreToken;
629
270
  _[AFTER_AFTER_FRAMESET_MODE][Tokenizer.EOF_TOKEN] = stopParsing;
630
271
 
631
- //Token utils
632
- function getTokenAttr(token, attrName) {
633
- for (var i = token.attrs.length - 1; i >= 0; i--) {
634
- if (token.attrs[i].name === attrName)
635
- return token.attrs[i].value;
636
- }
637
-
638
- return null;
639
- }
640
-
641
- function adjustTokenMathMLAttrs(token) {
642
- for (var i = 0; i < token.attrs.length; i++) {
643
- if (token.attrs[i].name === DEFINITION_URL_ATTR) {
644
- token.attrs[i].name = ADJUSTED_DEFINITION_URL_ATTR;
645
- break;
646
- }
647
- }
648
- }
649
-
650
- function adjustTokenSVGAttrs(token) {
651
- for (var i = 0; i < token.attrs.length; i++) {
652
- var adjustedAttrName = SVG_ATTRS_ADJUSTMENT_MAP[token.attrs[i].name];
653
-
654
- if (adjustedAttrName)
655
- token.attrs[i].name = adjustedAttrName;
656
- }
657
- }
658
-
659
- function adjustTokenForeignAttrs(token) {
660
- for (var i = 0; i < token.attrs.length; i++) {
661
- var adjustedAttrEntry = FOREIGN_ATTRS_ADJUSTMENT_MAP[token.attrs[i].name];
662
-
663
- if (adjustedAttrEntry) {
664
- token.attrs[i].prefix = adjustedAttrEntry.prefix;
665
- token.attrs[i].name = adjustedAttrEntry.name;
666
- token.attrs[i].namespace = adjustedAttrEntry.namespace;
667
- }
668
- }
669
- }
670
-
671
- function adjustTokenSVGTagName(token) {
672
- var adjustedTagName = SVG_TAG_NAMES_ADJUSTMENT_MAP[token.tagName];
673
-
674
- if (adjustedTagName)
675
- token.tagName = adjustedTagName;
676
- }
677
-
678
- //Foreign content validation
679
- function isValidForeignContentStartTag(startTagToken) {
680
- var tn = startTagToken.tagName;
681
-
682
- if (tn === $.FONT && (getTokenAttr(startTagToken, COLOR_ATTR) !== null ||
683
- getTokenAttr(startTagToken, FACE_ATTR) !== null ||
684
- getTokenAttr(startTagToken, SIZE_ATTR) !== null)) {
685
- return false;
686
- }
687
-
688
- return !NOT_ALLOWED_IN_FOREIGN_CONTENT[tn];
689
- }
690
-
691
- //Quirks mode
692
- function isQuirksDoctype(name, publicId, systemId) {
693
- if (name !== VALID_DOCTYPE_NAME)
694
- return true;
695
-
696
- if (systemId && systemId.toLowerCase() === QUIRKS_MODE_SYSTEM_ID)
697
- return true;
698
-
699
- if (publicId !== null) {
700
- publicId = publicId.toLowerCase();
701
-
702
- if (QUIRKS_MODE_PUBLIC_IDS.indexOf(publicId) > -1)
703
- return true;
704
-
705
- var prefixes = QUIRKS_MODE_PUBLIC_ID_PREFIXES;
706
-
707
- if (systemId === null)
708
- prefixes = prefixes.concat(QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES);
709
-
710
- for (var i = 0; i < prefixes.length; i++) {
711
- if (publicId.indexOf(prefixes[i]) === 0)
712
- return true;
713
- }
714
- }
715
-
716
- return false;
717
- }
718
-
719
272
  //Searchable index building utils (<isindex> tag)
720
273
  function getSearchableIndexFormAttrs(isindexStartTagToken) {
721
- var indexAction = getTokenAttr(isindexStartTagToken, ACTION_ATTR),
274
+ var indexAction = Tokenizer.getTokenAttr(isindexStartTagToken, ATTRS.ACTION),
722
275
  attrs = [];
723
276
 
724
277
  if (indexAction !== null) {
725
278
  attrs.push({
726
- name: ACTION_ATTR,
279
+ name: ATTRS.ACTION,
727
280
  value: indexAction
728
281
  });
729
282
  }
@@ -732,7 +285,7 @@ function getSearchableIndexFormAttrs(isindexStartTagToken) {
732
285
  }
733
286
 
734
287
  function getSearchableIndexLabelText(isindexStartTagToken) {
735
- var indexPrompt = getTokenAttr(isindexStartTagToken, PROMPT_ATTR);
288
+ var indexPrompt = Tokenizer.getTokenAttr(isindexStartTagToken, ATTRS.PROMPT);
736
289
 
737
290
  return indexPrompt === null ? SEARCHABLE_INDEX_DEFAULT_PROMPT : indexPrompt;
738
291
  }
@@ -744,12 +297,12 @@ function getSearchableIndexInputAttrs(isindexStartTagToken) {
744
297
  for (var i = 0; i < isindexAttrs.length; i++) {
745
298
  var name = isindexAttrs[i].name;
746
299
 
747
- if (name !== NAME_ATTR && name !== ACTION_ATTR && name !== PROMPT_ATTR)
300
+ if (name !== ATTRS.NAME && name !== ATTRS.ACTION && name !== ATTRS.PROMPT)
748
301
  inputAttrs.push(isindexAttrs[i]);
749
302
  }
750
303
 
751
304
  inputAttrs.push({
752
- name: NAME_ATTR,
305
+ name: ATTRS.NAME,
753
306
  value: SEARCHABLE_INDEX_INPUT_NAME
754
307
  });
755
308
 
@@ -758,7 +311,7 @@ function getSearchableIndexInputAttrs(isindexStartTagToken) {
758
311
 
759
312
  //Parser
760
313
  var Parser = module.exports = function (treeAdapter) {
761
- this.treeAdapter = treeAdapter || defaultTreeAdapter;
314
+ this.treeAdapter = treeAdapter || DefaultTreeAdapter;
762
315
  };
763
316
 
764
317
  //API
@@ -1041,30 +594,18 @@ Parser.prototype._processFakeEndTag = function (tagName) {
1041
594
 
1042
595
  //Integration points
1043
596
  Parser.prototype._isMathMLTextIntegrationPoint = function (element) {
1044
- var tn = this.treeAdapter.getTagName(element);
597
+ var tn = this.treeAdapter.getTagName(element),
598
+ ns = this.treeAdapter.getNamespaceURI(element);
1045
599
 
1046
- return this.treeAdapter.getNamespaceURI(element) === NS.MATHML &&
1047
- (tn === $.MI || tn === $.MO || tn === $.MN || tn === $.MS || tn === $.MTEXT);
600
+ return ForeignContent.isMathMLTextIntegrationPoint(tn, ns);
1048
601
  };
1049
602
 
1050
603
  Parser.prototype._isHtmlIntegrationPoint = function (element) {
1051
604
  var tn = this.treeAdapter.getTagName(element),
1052
- ns = this.treeAdapter.getNamespaceURI(element);
1053
-
1054
- if (ns === NS.MATHML && tn === $.ANNOTATION_XML) {
1055
- var attrs = this.treeAdapter.getAttrList(element);
1056
-
1057
- for (var i = 0; i < attrs.length; i++) {
1058
- if (attrs[i].name === ENCODING_ATTR) {
1059
- var value = attrs[i].value.toLowerCase();
605
+ ns = this.treeAdapter.getNamespaceURI(element),
606
+ attrs = this.treeAdapter.getAttrList(element);
1060
607
 
1061
- if (value === APPLICATION_XML_MIME_TYPE || value === TEXT_HTML_MIME_TYPE)
1062
- return true;
1063
- }
1064
- }
1065
- }
1066
-
1067
- return ns === NS.SVG && (tn === $.FOREIGN_OBJECT || tn === $.DESC || tn === $.TITLE);
608
+ return ForeignContent.isHtmlIntegrationPoint(tn, ns, attrs);
1068
609
  };
1069
610
 
1070
611
  //Active formatting elements reconstruction
@@ -1320,7 +861,7 @@ Parser.prototype._isSpecialElement = function (element) {
1320
861
  var tn = this.treeAdapter.getTagName(element),
1321
862
  ns = this.treeAdapter.getNamespaceURI(element);
1322
863
 
1323
- return SPECIAL_ELEMENTS[ns][tn];
864
+ return HTML.SPECIAL_ELEMENTS[ns][tn];
1324
865
  };
1325
866
 
1326
867
 
@@ -1355,7 +896,7 @@ function stopParsing(p, token) {
1355
896
  function doctypeInInitialMode(p, token) {
1356
897
  p._setDocumentType(token);
1357
898
 
1358
- if (token.forceQuirks || isQuirksDoctype(token.name, token.publicId, token.systemId))
899
+ if (token.forceQuirks || Doctype.isQuirks(token.name, token.publicId, token.systemId))
1359
900
  p.treeAdapter.setQuirksMode(p.document);
1360
901
 
1361
902
  p.insertionMode = BEFORE_HTML_MODE;
@@ -1698,7 +1239,7 @@ function inputStartTagInBody(p, token) {
1698
1239
  p._reconstructActiveFormattingElements();
1699
1240
  p._appendElement(token, NS.HTML);
1700
1241
 
1701
- var inputType = getTokenAttr(token, TYPE_ATTR);
1242
+ var inputType = Tokenizer.getTokenAttr(token, ATTRS.TYPE);
1702
1243
 
1703
1244
  if (!inputType || inputType.toLowerCase() !== HIDDEN_INPUT_TYPE)
1704
1245
  p.framesetOk = false;
@@ -1760,8 +1301,8 @@ function iframeStartTagInBody(p, token) {
1760
1301
  p._switchToTextParsing(token, Tokenizer.RAWTEXT_STATE);
1761
1302
  }
1762
1303
 
1763
- //NOTE: here we assume that we always act as an interactive user agent with enabled scripting, so we parse
1764
- //<noscript> as a rawtext.
1304
+ //NOTE: here we assume that we always act as an user agent with enabled plugins, so we parse
1305
+ //<noembed> as a rawtext.
1765
1306
  function noembedStartTagInBody(p, token) {
1766
1307
  p._switchToTextParsing(token, Tokenizer.RAWTEXT_STATE);
1767
1308
  }
@@ -1802,8 +1343,9 @@ function menuitemStartTagInBody(p, token) {
1802
1343
 
1803
1344
  function mathStartTagInBody(p, token) {
1804
1345
  p._reconstructActiveFormattingElements();
1805
- adjustTokenMathMLAttrs(token);
1806
- adjustTokenForeignAttrs(token);
1346
+
1347
+ ForeignContent.adjustTokenMathMLAttrs(token);
1348
+ ForeignContent.adjustTokenXMLAttrs(token);
1807
1349
 
1808
1350
  if (token.selfClosing)
1809
1351
  p._appendElement(token, NS.MATHML);
@@ -1813,8 +1355,9 @@ function mathStartTagInBody(p, token) {
1813
1355
 
1814
1356
  function svgStartTagInBody(p, token) {
1815
1357
  p._reconstructActiveFormattingElements();
1816
- adjustTokenSVGAttrs(token);
1817
- adjustTokenForeignAttrs(token);
1358
+
1359
+ ForeignContent.adjustTokenSVGAttrs(token);
1360
+ ForeignContent.adjustTokenXMLAttrs(token);
1818
1361
 
1819
1362
  if (token.selfClosing)
1820
1363
  p._appendElement(token, NS.SVG);
@@ -2378,7 +1921,7 @@ function tableStartTagInTable(p, token) {
2378
1921
  }
2379
1922
 
2380
1923
  function inputStartTagInTable(p, token) {
2381
- var inputType = getTokenAttr(token, TYPE_ATTR);
1924
+ var inputType = Tokenizer.getTokenAttr(token, ATTRS.TYPE);
2382
1925
 
2383
1926
  if (inputType && inputType.toLowerCase() === HIDDEN_INPUT_TYPE)
2384
1927
  p._appendElement(token, NS.HTML);
@@ -2981,7 +2524,7 @@ function characterInForeignContent(p, token) {
2981
2524
  }
2982
2525
 
2983
2526
  function startTagInForeignContent(p, token) {
2984
- if (!isValidForeignContentStartTag(token) && !p.fragmentContext) {
2527
+ if (ForeignContent.causesExit(token) && !p.fragmentContext) {
2985
2528
  while (p.treeAdapter.getNamespaceURI(p.openElements.current) !== NS.HTML &&
2986
2529
  (!p._isMathMLTextIntegrationPoint(p.openElements.current)) &&
2987
2530
  (!p._isHtmlIntegrationPoint(p.openElements.current))) {
@@ -2996,13 +2539,14 @@ function startTagInForeignContent(p, token) {
2996
2539
  currentNs = p.treeAdapter.getNamespaceURI(current);
2997
2540
 
2998
2541
  if (currentNs === NS.MATHML)
2999
- adjustTokenMathMLAttrs(token);
2542
+ ForeignContent.adjustTokenMathMLAttrs(token);
2543
+
3000
2544
  else if (currentNs === NS.SVG) {
3001
- adjustTokenSVGTagName(token);
3002
- adjustTokenSVGAttrs(token);
2545
+ ForeignContent.adjustTokenSVGTagName(token);
2546
+ ForeignContent.adjustTokenSVGAttrs(token);
3003
2547
  }
3004
2548
 
3005
- adjustTokenForeignAttrs(token);
2549
+ ForeignContent.adjustTokenXMLAttrs(token);
3006
2550
 
3007
2551
  if (token.selfClosing)
3008
2552
  p._appendElement(token, currentNs);
@@ -1,5 +1,5 @@
1
- var defaultTreeAdapter = require('../tree_adapters/default'),
2
- HTML = require('../const/html');
1
+ var DefaultTreeAdapter = require('../tree_adapters/default'),
2
+ HTML = require('../common/html');
3
3
 
4
4
  //Aliases
5
5
  var $ = HTML.TAG_NAMES,
@@ -42,7 +42,7 @@ function enquoteDoctypeId(id) {
42
42
 
43
43
  //TreeSerializer
44
44
  var TreeSerializer = module.exports = function (treeAdapter) {
45
- this.treeAdapter = treeAdapter || defaultTreeAdapter;
45
+ this.treeAdapter = treeAdapter || DefaultTreeAdapter;
46
46
  };
47
47
 
48
48
 
@@ -176,4 +176,3 @@ TreeSerializer.prototype._serializeDocumentTypeNode = function (node) {
176
176
 
177
177
  this.html += '>';
178
178
  };
179
-