parse5 2.1.5 → 2.2.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.
package/LICENSE CHANGED
@@ -1,19 +1,19 @@
1
- Copyright (c) 2013-2016 Ivan Nikulin (ifaaan@gmail.com, https://github.com/inikulin)
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
1
+ Copyright (c) 2013-2016 Ivan Nikulin (ifaaan@gmail.com, https://github.com/inikulin)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,40 +1,40 @@
1
- <p align="center">
2
- <a href="https://github.com/inikulin/parse5">
3
- <img src="https://raw.github.com/inikulin/parse5/master/docs/logo.png" alt="parse5" />
4
- </a>
5
- </p>
6
-
7
- <p align="center">
8
- <i>WHATWG HTML5 specification-compliant, fast and ready for production HTML parsing/serialization toolset for Node.js</i>
9
- </p>
10
-
11
- <p align="center">
12
- <a href="https://travis-ci.org/inikulin/parse5"><img alt="Build Status" src="https://api.travis-ci.org/inikulin/parse5.svg"></a>
13
- <a href="https://www.npmjs.com/package/parse5"><img alt="NPM Version" src="https://img.shields.io/npm/v/parse5.svg"></a>
14
- <a href="https://npmjs.org/package/parse5"><img alt="Downloads" src="http://img.shields.io/npm/dm/parse5.svg"></a>
15
- <a href="https://npmjs.org/package/parse5"><img alt="Downloads total" src="http://img.shields.io/npm/dt/parse5.svg"></a>
16
- </p>
17
-
18
- <p align="center">
19
- <b><i>parse5</i></b> provides nearly everything you may need when dealing with HTML. It's the fastest spec-compliant HTML parser
20
- for Node to date. It parses HTML the way the latest version of your browser does. It has proven itself reliable in such projects
21
- as <a href="https://github.com/tmpvar/jsdom">jsdom</a>, <a href="https://github.com/angular/angular">Angular2</a>, <a href="https://www.polymer-project.org">Polymer</a> and many more.
22
- </p>
23
-
24
- ----
25
-
26
- <p align="center">
27
- <a href="https://github.com/inikulin/parse5/wiki/Documentation">Documentation</a>
28
- </p>
29
-
30
- <p align="center">
31
- <a href="https://github.com/inikulin/parse5/wiki/Documentation#version-history">Version history</a>
32
- </p>
33
-
34
- <p align="center">
35
- <a href="http://astexplorer.net/#/1CHlCXc4n4">Online playground</a>
36
- </p>
37
-
38
- <p align="center">
39
- <a href="https://github.com/inikulin/parse5/issues">Issue tracker</a>
40
- </p>
1
+ <p align="center">
2
+ <a href="https://github.com/inikulin/parse5">
3
+ <img src="https://raw.github.com/inikulin/parse5/master/docs/logo.png" alt="parse5" />
4
+ </a>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <i>WHATWG HTML5 specification-compliant, fast and ready for production HTML parsing/serialization toolset for Node.js</i>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://travis-ci.org/inikulin/parse5"><img alt="Build Status" src="https://api.travis-ci.org/inikulin/parse5.svg"></a>
13
+ <a href="https://www.npmjs.com/package/parse5"><img alt="NPM Version" src="https://img.shields.io/npm/v/parse5.svg"></a>
14
+ <a href="https://npmjs.org/package/parse5"><img alt="Downloads" src="http://img.shields.io/npm/dm/parse5.svg"></a>
15
+ <a href="https://npmjs.org/package/parse5"><img alt="Downloads total" src="http://img.shields.io/npm/dt/parse5.svg"></a>
16
+ </p>
17
+
18
+ <p align="center">
19
+ <b><i>parse5</i></b> provides nearly everything you may need when dealing with HTML. It's the fastest spec-compliant HTML parser
20
+ for Node to date. It parses HTML the way the latest version of your browser does. It has proven itself reliable in such projects
21
+ as <a href="https://github.com/tmpvar/jsdom">jsdom</a>, <a href="https://github.com/angular/angular">Angular2</a>, <a href="https://www.polymer-project.org">Polymer</a> and many more.
22
+ </p>
23
+
24
+ ----
25
+
26
+ <p align="center">
27
+ <a href="https://github.com/inikulin/parse5/wiki/Documentation">Documentation</a>
28
+ </p>
29
+
30
+ <p align="center">
31
+ <a href="https://github.com/inikulin/parse5/wiki/Documentation#version-history">Version history</a>
32
+ </p>
33
+
34
+ <p align="center">
35
+ <a href="http://astexplorer.net/#/1CHlCXc4n4">Online playground</a>
36
+ </p>
37
+
38
+ <p align="center">
39
+ <a href="https://github.com/inikulin/parse5/issues">Issue tracker</a>
40
+ </p>
@@ -121,7 +121,7 @@ exports.isQuirks = function (name, publicId, systemId) {
121
121
  exports.serializeContent = function (name, publicId, systemId) {
122
122
  var str = '!DOCTYPE ';
123
123
 
124
- if(name)
124
+ if (name)
125
125
  str += name;
126
126
 
127
127
  if (publicId !== null)
@@ -1,250 +1,260 @@
1
- 'use strict';
2
-
3
- var Tokenizer = require('../tokenizer'),
4
- HTML = require('./html');
5
-
6
- //Aliases
7
- var $ = HTML.TAG_NAMES,
8
- NS = HTML.NAMESPACES,
9
- ATTRS = HTML.ATTRS;
10
-
11
-
12
- //MIME types
13
- var MIME_TYPES = {
14
- TEXT_HTML: 'text/html',
15
- APPLICATION_XML: 'application/xhtml+xml'
16
- };
17
-
18
- //Attributes
19
- var DEFINITION_URL_ATTR = 'definitionurl',
20
- ADJUSTED_DEFINITION_URL_ATTR = 'definitionURL',
21
- SVG_ATTRS_ADJUSTMENT_MAP = {
22
- 'attributename': 'attributeName',
23
- 'attributetype': 'attributeType',
24
- 'basefrequency': 'baseFrequency',
25
- 'baseprofile': 'baseProfile',
26
- 'calcmode': 'calcMode',
27
- 'clippathunits': 'clipPathUnits',
28
- 'diffuseconstant': 'diffuseConstant',
29
- 'edgemode': 'edgeMode',
30
- 'filterunits': 'filterUnits',
31
- 'glyphref': 'glyphRef',
32
- 'gradienttransform': 'gradientTransform',
33
- 'gradientunits': 'gradientUnits',
34
- 'kernelmatrix': 'kernelMatrix',
35
- 'kernelunitlength': 'kernelUnitLength',
36
- 'keypoints': 'keyPoints',
37
- 'keysplines': 'keySplines',
38
- 'keytimes': 'keyTimes',
39
- 'lengthadjust': 'lengthAdjust',
40
- 'limitingconeangle': 'limitingConeAngle',
41
- 'markerheight': 'markerHeight',
42
- 'markerunits': 'markerUnits',
43
- 'markerwidth': 'markerWidth',
44
- 'maskcontentunits': 'maskContentUnits',
45
- 'maskunits': 'maskUnits',
46
- 'numoctaves': 'numOctaves',
47
- 'pathlength': 'pathLength',
48
- 'patterncontentunits': 'patternContentUnits',
49
- 'patterntransform': 'patternTransform',
50
- 'patternunits': 'patternUnits',
51
- 'pointsatx': 'pointsAtX',
52
- 'pointsaty': 'pointsAtY',
53
- 'pointsatz': 'pointsAtZ',
54
- 'preservealpha': 'preserveAlpha',
55
- 'preserveaspectratio': 'preserveAspectRatio',
56
- 'primitiveunits': 'primitiveUnits',
57
- 'refx': 'refX',
58
- 'refy': 'refY',
59
- 'repeatcount': 'repeatCount',
60
- 'repeatdur': 'repeatDur',
61
- 'requiredextensions': 'requiredExtensions',
62
- 'requiredfeatures': 'requiredFeatures',
63
- 'specularconstant': 'specularConstant',
64
- 'specularexponent': 'specularExponent',
65
- 'spreadmethod': 'spreadMethod',
66
- 'startoffset': 'startOffset',
67
- 'stddeviation': 'stdDeviation',
68
- 'stitchtiles': 'stitchTiles',
69
- 'surfacescale': 'surfaceScale',
70
- 'systemlanguage': 'systemLanguage',
71
- 'tablevalues': 'tableValues',
72
- 'targetx': 'targetX',
73
- 'targety': 'targetY',
74
- 'textlength': 'textLength',
75
- 'viewbox': 'viewBox',
76
- 'viewtarget': 'viewTarget',
77
- 'xchannelselector': 'xChannelSelector',
78
- 'ychannelselector': 'yChannelSelector',
79
- 'zoomandpan': 'zoomAndPan'
80
- },
81
- XML_ATTRS_ADJUSTMENT_MAP = {
82
- 'xlink:actuate': {prefix: 'xlink', name: 'actuate', namespace: NS.XLINK},
83
- 'xlink:arcrole': {prefix: 'xlink', name: 'arcrole', namespace: NS.XLINK},
84
- 'xlink:href': {prefix: 'xlink', name: 'href', namespace: NS.XLINK},
85
- 'xlink:role': {prefix: 'xlink', name: 'role', namespace: NS.XLINK},
86
- 'xlink:show': {prefix: 'xlink', name: 'show', namespace: NS.XLINK},
87
- 'xlink:title': {prefix: 'xlink', name: 'title', namespace: NS.XLINK},
88
- 'xlink:type': {prefix: 'xlink', name: 'type', namespace: NS.XLINK},
89
- 'xml:base': {prefix: 'xml', name: 'base', namespace: NS.XML},
90
- 'xml:lang': {prefix: 'xml', name: 'lang', namespace: NS.XML},
91
- 'xml:space': {prefix: 'xml', name: 'space', namespace: NS.XML},
92
- 'xmlns': {prefix: '', name: 'xmlns', namespace: NS.XMLNS},
93
- 'xmlns:xlink': {prefix: 'xmlns', name: 'xlink', namespace: NS.XMLNS}
94
-
95
- };
96
-
97
- //SVG tag names adjustment map
98
- var SVG_TAG_NAMES_ADJUSTMENT_MAP = {
99
- 'altglyph': 'altGlyph',
100
- 'altglyphdef': 'altGlyphDef',
101
- 'altglyphitem': 'altGlyphItem',
102
- 'animatecolor': 'animateColor',
103
- 'animatemotion': 'animateMotion',
104
- 'animatetransform': 'animateTransform',
105
- 'clippath': 'clipPath',
106
- 'feblend': 'feBlend',
107
- 'fecolormatrix': 'feColorMatrix',
108
- 'fecomponenttransfer': 'feComponentTransfer',
109
- 'fecomposite': 'feComposite',
110
- 'feconvolvematrix': 'feConvolveMatrix',
111
- 'fediffuselighting': 'feDiffuseLighting',
112
- 'fedisplacementmap': 'feDisplacementMap',
113
- 'fedistantlight': 'feDistantLight',
114
- 'feflood': 'feFlood',
115
- 'fefunca': 'feFuncA',
116
- 'fefuncb': 'feFuncB',
117
- 'fefuncg': 'feFuncG',
118
- 'fefuncr': 'feFuncR',
119
- 'fegaussianblur': 'feGaussianBlur',
120
- 'feimage': 'feImage',
121
- 'femerge': 'feMerge',
122
- 'femergenode': 'feMergeNode',
123
- 'femorphology': 'feMorphology',
124
- 'feoffset': 'feOffset',
125
- 'fepointlight': 'fePointLight',
126
- 'fespecularlighting': 'feSpecularLighting',
127
- 'fespotlight': 'feSpotLight',
128
- 'fetile': 'feTile',
129
- 'feturbulence': 'feTurbulence',
130
- 'foreignobject': 'foreignObject',
131
- 'glyphref': 'glyphRef',
132
- 'lineargradient': 'linearGradient',
133
- 'radialgradient': 'radialGradient',
134
- 'textpath': 'textPath'
135
- };
136
-
137
- //Tags that causes exit from foreign content
138
- var EXITS_FOREIGN_CONTENT = {};
139
-
140
- EXITS_FOREIGN_CONTENT[$.B] = true;
141
- EXITS_FOREIGN_CONTENT[$.BIG] = true;
142
- EXITS_FOREIGN_CONTENT[$.BLOCKQUOTE] = true;
143
- EXITS_FOREIGN_CONTENT[$.BODY] = true;
144
- EXITS_FOREIGN_CONTENT[$.BR] = true;
145
- EXITS_FOREIGN_CONTENT[$.CENTER] = true;
146
- EXITS_FOREIGN_CONTENT[$.CODE] = true;
147
- EXITS_FOREIGN_CONTENT[$.DD] = true;
148
- EXITS_FOREIGN_CONTENT[$.DIV] = true;
149
- EXITS_FOREIGN_CONTENT[$.DL] = true;
150
- EXITS_FOREIGN_CONTENT[$.DT] = true;
151
- EXITS_FOREIGN_CONTENT[$.EM] = true;
152
- EXITS_FOREIGN_CONTENT[$.EMBED] = true;
153
- EXITS_FOREIGN_CONTENT[$.H1] = true;
154
- EXITS_FOREIGN_CONTENT[$.H2] = true;
155
- EXITS_FOREIGN_CONTENT[$.H3] = true;
156
- EXITS_FOREIGN_CONTENT[$.H4] = true;
157
- EXITS_FOREIGN_CONTENT[$.H5] = true;
158
- EXITS_FOREIGN_CONTENT[$.H6] = true;
159
- EXITS_FOREIGN_CONTENT[$.HEAD] = true;
160
- EXITS_FOREIGN_CONTENT[$.HR] = true;
161
- EXITS_FOREIGN_CONTENT[$.I] = true;
162
- EXITS_FOREIGN_CONTENT[$.IMG] = true;
163
- EXITS_FOREIGN_CONTENT[$.LI] = true;
164
- EXITS_FOREIGN_CONTENT[$.LISTING] = true;
165
- EXITS_FOREIGN_CONTENT[$.MENU] = true;
166
- EXITS_FOREIGN_CONTENT[$.META] = true;
167
- EXITS_FOREIGN_CONTENT[$.NOBR] = true;
168
- EXITS_FOREIGN_CONTENT[$.OL] = true;
169
- EXITS_FOREIGN_CONTENT[$.P] = true;
170
- EXITS_FOREIGN_CONTENT[$.PRE] = true;
171
- EXITS_FOREIGN_CONTENT[$.RUBY] = true;
172
- EXITS_FOREIGN_CONTENT[$.S] = true;
173
- EXITS_FOREIGN_CONTENT[$.SMALL] = true;
174
- EXITS_FOREIGN_CONTENT[$.SPAN] = true;
175
- EXITS_FOREIGN_CONTENT[$.STRONG] = true;
176
- EXITS_FOREIGN_CONTENT[$.STRIKE] = true;
177
- EXITS_FOREIGN_CONTENT[$.SUB] = true;
178
- EXITS_FOREIGN_CONTENT[$.SUP] = true;
179
- EXITS_FOREIGN_CONTENT[$.TABLE] = true;
180
- EXITS_FOREIGN_CONTENT[$.TT] = true;
181
- EXITS_FOREIGN_CONTENT[$.U] = true;
182
- EXITS_FOREIGN_CONTENT[$.UL] = true;
183
- EXITS_FOREIGN_CONTENT[$.VAR] = true;
184
-
185
- //Check exit from foreign content
186
- exports.causesExit = function (startTagToken) {
187
- var tn = startTagToken.tagName;
188
- var isFontWithAttrs = tn === $.FONT && (Tokenizer.getTokenAttr(startTagToken, ATTRS.COLOR) !== null ||
189
- Tokenizer.getTokenAttr(startTagToken, ATTRS.SIZE) !== null ||
190
- Tokenizer.getTokenAttr(startTagToken, ATTRS.FACE) !== null);
191
-
192
- return isFontWithAttrs ? true : EXITS_FOREIGN_CONTENT[tn];
193
- };
194
-
195
- //Token adjustments
196
- exports.adjustTokenMathMLAttrs = function (token) {
197
- for (var i = 0; i < token.attrs.length; i++) {
198
- if (token.attrs[i].name === DEFINITION_URL_ATTR) {
199
- token.attrs[i].name = ADJUSTED_DEFINITION_URL_ATTR;
200
- break;
201
- }
202
- }
203
- };
204
-
205
- exports.adjustTokenSVGAttrs = function (token) {
206
- for (var i = 0; i < token.attrs.length; i++) {
207
- var adjustedAttrName = SVG_ATTRS_ADJUSTMENT_MAP[token.attrs[i].name];
208
-
209
- if (adjustedAttrName)
210
- token.attrs[i].name = adjustedAttrName;
211
- }
212
- };
213
-
214
- exports.adjustTokenXMLAttrs = function (token) {
215
- for (var i = 0; i < token.attrs.length; i++) {
216
- var adjustedAttrEntry = XML_ATTRS_ADJUSTMENT_MAP[token.attrs[i].name];
217
-
218
- if (adjustedAttrEntry) {
219
- token.attrs[i].prefix = adjustedAttrEntry.prefix;
220
- token.attrs[i].name = adjustedAttrEntry.name;
221
- token.attrs[i].namespace = adjustedAttrEntry.namespace;
222
- }
223
- }
224
- };
225
-
226
- exports.adjustTokenSVGTagName = function (token) {
227
- var adjustedTagName = SVG_TAG_NAMES_ADJUSTMENT_MAP[token.tagName];
228
-
229
- if (adjustedTagName)
230
- token.tagName = adjustedTagName;
231
- };
232
-
233
- //Integration points
234
- exports.isMathMLTextIntegrationPoint = function (tn, ns) {
235
- return ns === NS.MATHML && (tn === $.MI || tn === $.MO || tn === $.MN || tn === $.MS || tn === $.MTEXT);
236
- };
237
-
238
- exports.isHtmlIntegrationPoint = function (tn, ns, attrs) {
239
- if (ns === NS.MATHML && tn === $.ANNOTATION_XML) {
240
- for (var i = 0; i < attrs.length; i++) {
241
- if (attrs[i].name === ATTRS.ENCODING) {
242
- var value = attrs[i].value.toLowerCase();
243
-
244
- return value === MIME_TYPES.TEXT_HTML || value === MIME_TYPES.APPLICATION_XML;
245
- }
246
- }
247
- }
248
-
249
- return ns === NS.SVG && (tn === $.FOREIGN_OBJECT || tn === $.DESC || tn === $.TITLE);
250
- };
1
+ 'use strict';
2
+
3
+ var Tokenizer = require('../tokenizer'),
4
+ HTML = require('./html');
5
+
6
+ //Aliases
7
+ var $ = HTML.TAG_NAMES,
8
+ NS = HTML.NAMESPACES,
9
+ ATTRS = HTML.ATTRS;
10
+
11
+
12
+ //MIME types
13
+ var MIME_TYPES = {
14
+ TEXT_HTML: 'text/html',
15
+ APPLICATION_XML: 'application/xhtml+xml'
16
+ };
17
+
18
+ //Attributes
19
+ var DEFINITION_URL_ATTR = 'definitionurl',
20
+ ADJUSTED_DEFINITION_URL_ATTR = 'definitionURL',
21
+ SVG_ATTRS_ADJUSTMENT_MAP = {
22
+ 'attributename': 'attributeName',
23
+ 'attributetype': 'attributeType',
24
+ 'basefrequency': 'baseFrequency',
25
+ 'baseprofile': 'baseProfile',
26
+ 'calcmode': 'calcMode',
27
+ 'clippathunits': 'clipPathUnits',
28
+ 'diffuseconstant': 'diffuseConstant',
29
+ 'edgemode': 'edgeMode',
30
+ 'filterunits': 'filterUnits',
31
+ 'glyphref': 'glyphRef',
32
+ 'gradienttransform': 'gradientTransform',
33
+ 'gradientunits': 'gradientUnits',
34
+ 'kernelmatrix': 'kernelMatrix',
35
+ 'kernelunitlength': 'kernelUnitLength',
36
+ 'keypoints': 'keyPoints',
37
+ 'keysplines': 'keySplines',
38
+ 'keytimes': 'keyTimes',
39
+ 'lengthadjust': 'lengthAdjust',
40
+ 'limitingconeangle': 'limitingConeAngle',
41
+ 'markerheight': 'markerHeight',
42
+ 'markerunits': 'markerUnits',
43
+ 'markerwidth': 'markerWidth',
44
+ 'maskcontentunits': 'maskContentUnits',
45
+ 'maskunits': 'maskUnits',
46
+ 'numoctaves': 'numOctaves',
47
+ 'pathlength': 'pathLength',
48
+ 'patterncontentunits': 'patternContentUnits',
49
+ 'patterntransform': 'patternTransform',
50
+ 'patternunits': 'patternUnits',
51
+ 'pointsatx': 'pointsAtX',
52
+ 'pointsaty': 'pointsAtY',
53
+ 'pointsatz': 'pointsAtZ',
54
+ 'preservealpha': 'preserveAlpha',
55
+ 'preserveaspectratio': 'preserveAspectRatio',
56
+ 'primitiveunits': 'primitiveUnits',
57
+ 'refx': 'refX',
58
+ 'refy': 'refY',
59
+ 'repeatcount': 'repeatCount',
60
+ 'repeatdur': 'repeatDur',
61
+ 'requiredextensions': 'requiredExtensions',
62
+ 'requiredfeatures': 'requiredFeatures',
63
+ 'specularconstant': 'specularConstant',
64
+ 'specularexponent': 'specularExponent',
65
+ 'spreadmethod': 'spreadMethod',
66
+ 'startoffset': 'startOffset',
67
+ 'stddeviation': 'stdDeviation',
68
+ 'stitchtiles': 'stitchTiles',
69
+ 'surfacescale': 'surfaceScale',
70
+ 'systemlanguage': 'systemLanguage',
71
+ 'tablevalues': 'tableValues',
72
+ 'targetx': 'targetX',
73
+ 'targety': 'targetY',
74
+ 'textlength': 'textLength',
75
+ 'viewbox': 'viewBox',
76
+ 'viewtarget': 'viewTarget',
77
+ 'xchannelselector': 'xChannelSelector',
78
+ 'ychannelselector': 'yChannelSelector',
79
+ 'zoomandpan': 'zoomAndPan'
80
+ },
81
+ XML_ATTRS_ADJUSTMENT_MAP = {
82
+ 'xlink:actuate': {prefix: 'xlink', name: 'actuate', namespace: NS.XLINK},
83
+ 'xlink:arcrole': {prefix: 'xlink', name: 'arcrole', namespace: NS.XLINK},
84
+ 'xlink:href': {prefix: 'xlink', name: 'href', namespace: NS.XLINK},
85
+ 'xlink:role': {prefix: 'xlink', name: 'role', namespace: NS.XLINK},
86
+ 'xlink:show': {prefix: 'xlink', name: 'show', namespace: NS.XLINK},
87
+ 'xlink:title': {prefix: 'xlink', name: 'title', namespace: NS.XLINK},
88
+ 'xlink:type': {prefix: 'xlink', name: 'type', namespace: NS.XLINK},
89
+ 'xml:base': {prefix: 'xml', name: 'base', namespace: NS.XML},
90
+ 'xml:lang': {prefix: 'xml', name: 'lang', namespace: NS.XML},
91
+ 'xml:space': {prefix: 'xml', name: 'space', namespace: NS.XML},
92
+ 'xmlns': {prefix: '', name: 'xmlns', namespace: NS.XMLNS},
93
+ 'xmlns:xlink': {prefix: 'xmlns', name: 'xlink', namespace: NS.XMLNS}
94
+
95
+ };
96
+
97
+ //SVG tag names adjustment map
98
+ var SVG_TAG_NAMES_ADJUSTMENT_MAP = exports.SVG_TAG_NAMES_ADJUSTMENT_MAP = {
99
+ 'altglyph': 'altGlyph',
100
+ 'altglyphdef': 'altGlyphDef',
101
+ 'altglyphitem': 'altGlyphItem',
102
+ 'animatecolor': 'animateColor',
103
+ 'animatemotion': 'animateMotion',
104
+ 'animatetransform': 'animateTransform',
105
+ 'clippath': 'clipPath',
106
+ 'feblend': 'feBlend',
107
+ 'fecolormatrix': 'feColorMatrix',
108
+ 'fecomponenttransfer': 'feComponentTransfer',
109
+ 'fecomposite': 'feComposite',
110
+ 'feconvolvematrix': 'feConvolveMatrix',
111
+ 'fediffuselighting': 'feDiffuseLighting',
112
+ 'fedisplacementmap': 'feDisplacementMap',
113
+ 'fedistantlight': 'feDistantLight',
114
+ 'feflood': 'feFlood',
115
+ 'fefunca': 'feFuncA',
116
+ 'fefuncb': 'feFuncB',
117
+ 'fefuncg': 'feFuncG',
118
+ 'fefuncr': 'feFuncR',
119
+ 'fegaussianblur': 'feGaussianBlur',
120
+ 'feimage': 'feImage',
121
+ 'femerge': 'feMerge',
122
+ 'femergenode': 'feMergeNode',
123
+ 'femorphology': 'feMorphology',
124
+ 'feoffset': 'feOffset',
125
+ 'fepointlight': 'fePointLight',
126
+ 'fespecularlighting': 'feSpecularLighting',
127
+ 'fespotlight': 'feSpotLight',
128
+ 'fetile': 'feTile',
129
+ 'feturbulence': 'feTurbulence',
130
+ 'foreignobject': 'foreignObject',
131
+ 'glyphref': 'glyphRef',
132
+ 'lineargradient': 'linearGradient',
133
+ 'radialgradient': 'radialGradient',
134
+ 'textpath': 'textPath'
135
+ };
136
+
137
+ //Tags that causes exit from foreign content
138
+ var EXITS_FOREIGN_CONTENT = {};
139
+
140
+ EXITS_FOREIGN_CONTENT[$.B] = true;
141
+ EXITS_FOREIGN_CONTENT[$.BIG] = true;
142
+ EXITS_FOREIGN_CONTENT[$.BLOCKQUOTE] = true;
143
+ EXITS_FOREIGN_CONTENT[$.BODY] = true;
144
+ EXITS_FOREIGN_CONTENT[$.BR] = true;
145
+ EXITS_FOREIGN_CONTENT[$.CENTER] = true;
146
+ EXITS_FOREIGN_CONTENT[$.CODE] = true;
147
+ EXITS_FOREIGN_CONTENT[$.DD] = true;
148
+ EXITS_FOREIGN_CONTENT[$.DIV] = true;
149
+ EXITS_FOREIGN_CONTENT[$.DL] = true;
150
+ EXITS_FOREIGN_CONTENT[$.DT] = true;
151
+ EXITS_FOREIGN_CONTENT[$.EM] = true;
152
+ EXITS_FOREIGN_CONTENT[$.EMBED] = true;
153
+ EXITS_FOREIGN_CONTENT[$.H1] = true;
154
+ EXITS_FOREIGN_CONTENT[$.H2] = true;
155
+ EXITS_FOREIGN_CONTENT[$.H3] = true;
156
+ EXITS_FOREIGN_CONTENT[$.H4] = true;
157
+ EXITS_FOREIGN_CONTENT[$.H5] = true;
158
+ EXITS_FOREIGN_CONTENT[$.H6] = true;
159
+ EXITS_FOREIGN_CONTENT[$.HEAD] = true;
160
+ EXITS_FOREIGN_CONTENT[$.HR] = true;
161
+ EXITS_FOREIGN_CONTENT[$.I] = true;
162
+ EXITS_FOREIGN_CONTENT[$.IMG] = true;
163
+ EXITS_FOREIGN_CONTENT[$.LI] = true;
164
+ EXITS_FOREIGN_CONTENT[$.LISTING] = true;
165
+ EXITS_FOREIGN_CONTENT[$.MENU] = true;
166
+ EXITS_FOREIGN_CONTENT[$.META] = true;
167
+ EXITS_FOREIGN_CONTENT[$.NOBR] = true;
168
+ EXITS_FOREIGN_CONTENT[$.OL] = true;
169
+ EXITS_FOREIGN_CONTENT[$.P] = true;
170
+ EXITS_FOREIGN_CONTENT[$.PRE] = true;
171
+ EXITS_FOREIGN_CONTENT[$.RUBY] = true;
172
+ EXITS_FOREIGN_CONTENT[$.S] = true;
173
+ EXITS_FOREIGN_CONTENT[$.SMALL] = true;
174
+ EXITS_FOREIGN_CONTENT[$.SPAN] = true;
175
+ EXITS_FOREIGN_CONTENT[$.STRONG] = true;
176
+ EXITS_FOREIGN_CONTENT[$.STRIKE] = true;
177
+ EXITS_FOREIGN_CONTENT[$.SUB] = true;
178
+ EXITS_FOREIGN_CONTENT[$.SUP] = true;
179
+ EXITS_FOREIGN_CONTENT[$.TABLE] = true;
180
+ EXITS_FOREIGN_CONTENT[$.TT] = true;
181
+ EXITS_FOREIGN_CONTENT[$.U] = true;
182
+ EXITS_FOREIGN_CONTENT[$.UL] = true;
183
+ EXITS_FOREIGN_CONTENT[$.VAR] = true;
184
+
185
+ //Check exit from foreign content
186
+ exports.causesExit = function (startTagToken) {
187
+ var tn = startTagToken.tagName;
188
+ var isFontWithAttrs = tn === $.FONT && (Tokenizer.getTokenAttr(startTagToken, ATTRS.COLOR) !== null ||
189
+ Tokenizer.getTokenAttr(startTagToken, ATTRS.SIZE) !== null ||
190
+ Tokenizer.getTokenAttr(startTagToken, ATTRS.FACE) !== null);
191
+
192
+ return isFontWithAttrs ? true : EXITS_FOREIGN_CONTENT[tn];
193
+ };
194
+
195
+ //Token adjustments
196
+ exports.adjustTokenMathMLAttrs = function (token) {
197
+ for (var i = 0; i < token.attrs.length; i++) {
198
+ if (token.attrs[i].name === DEFINITION_URL_ATTR) {
199
+ token.attrs[i].name = ADJUSTED_DEFINITION_URL_ATTR;
200
+ break;
201
+ }
202
+ }
203
+ };
204
+
205
+ exports.adjustTokenSVGAttrs = function (token) {
206
+ for (var i = 0; i < token.attrs.length; i++) {
207
+ var adjustedAttrName = SVG_ATTRS_ADJUSTMENT_MAP[token.attrs[i].name];
208
+
209
+ if (adjustedAttrName)
210
+ token.attrs[i].name = adjustedAttrName;
211
+ }
212
+ };
213
+
214
+ exports.adjustTokenXMLAttrs = function (token) {
215
+ for (var i = 0; i < token.attrs.length; i++) {
216
+ var adjustedAttrEntry = XML_ATTRS_ADJUSTMENT_MAP[token.attrs[i].name];
217
+
218
+ if (adjustedAttrEntry) {
219
+ token.attrs[i].prefix = adjustedAttrEntry.prefix;
220
+ token.attrs[i].name = adjustedAttrEntry.name;
221
+ token.attrs[i].namespace = adjustedAttrEntry.namespace;
222
+ }
223
+ }
224
+ };
225
+
226
+ exports.adjustTokenSVGTagName = function (token) {
227
+ var adjustedTagName = SVG_TAG_NAMES_ADJUSTMENT_MAP[token.tagName];
228
+
229
+ if (adjustedTagName)
230
+ token.tagName = adjustedTagName;
231
+ };
232
+
233
+ //Integration points
234
+ function isMathMLTextIntegrationPoint(tn, ns) {
235
+ return ns === NS.MATHML && (tn === $.MI || tn === $.MO || tn === $.MN || tn === $.MS || tn === $.MTEXT);
236
+ }
237
+
238
+ function isHtmlIntegrationPoint(tn, ns, attrs) {
239
+ if (ns === NS.MATHML && tn === $.ANNOTATION_XML) {
240
+ for (var i = 0; i < attrs.length; i++) {
241
+ if (attrs[i].name === ATTRS.ENCODING) {
242
+ var value = attrs[i].value.toLowerCase();
243
+
244
+ return value === MIME_TYPES.TEXT_HTML || value === MIME_TYPES.APPLICATION_XML;
245
+ }
246
+ }
247
+ }
248
+
249
+ return ns === NS.SVG && (tn === $.FOREIGN_OBJECT || tn === $.DESC || tn === $.TITLE);
250
+ }
251
+
252
+ exports.isIntegrationPoint = function (tn, ns, attrs, foreignNS) {
253
+ if ((!foreignNS || foreignNS === NS.HTML) && isHtmlIntegrationPoint(tn, ns, attrs))
254
+ return true;
255
+
256
+ if ((!foreignNS || foreignNS === NS.MATHML) && isMathMLTextIntegrationPoint(tn, ns))
257
+ return true;
258
+
259
+ return false;
260
+ };