parse5 4.0.0-test → 5.1.1
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 +1 -1
- package/README.md +14 -16
- package/lib/common/doctype.js +114 -108
- package/lib/common/error-codes.js +65 -0
- package/lib/common/foreign-content.js +265 -0
- package/lib/common/html.js +102 -102
- package/lib/common/unicode.js +81 -19
- package/lib/extensions/error-reporting/mixin-base.js +43 -0
- package/lib/extensions/error-reporting/parser-mixin.js +52 -0
- package/lib/extensions/error-reporting/preprocessor-mixin.js +24 -0
- package/lib/extensions/error-reporting/tokenizer-mixin.js +17 -0
- package/lib/extensions/location-info/open-element-stack-mixin.js +35 -0
- package/lib/extensions/location-info/parser-mixin.js +222 -0
- package/lib/extensions/location-info/tokenizer-mixin.js +146 -0
- package/lib/extensions/position-tracking/preprocessor-mixin.js +64 -0
- package/lib/index.js +6 -43
- package/lib/parser/formatting-element-list.js +181 -0
- package/lib/parser/index.js +1469 -1332
- package/lib/parser/open-element-stack.js +482 -0
- package/lib/serializer/index.js +136 -122
- package/lib/tokenizer/index.js +1856 -1804
- package/lib/tokenizer/{named_entity_data.js → named-entity-data.js} +1 -1
- package/lib/tokenizer/preprocessor.js +115 -103
- package/lib/tree-adapters/default.js +217 -0
- package/lib/utils/{merge_options.js → merge-options.js} +2 -2
- package/lib/utils/mixin.js +33 -12
- package/package.json +33 -58
- package/lib/common/foreign_content.js +0 -260
- package/lib/extensions/location_info/open_element_stack_mixin.js +0 -34
- package/lib/extensions/location_info/parser_mixin.js +0 -213
- package/lib/extensions/location_info/tokenizer_mixin.js +0 -117
- package/lib/extensions/position_tracking/preprocessor_mixin.js +0 -72
- package/lib/index.d.ts +0 -1077
- package/lib/parser/formatting_element_list.js +0 -167
- package/lib/parser/open_element_stack.js +0 -395
- package/lib/parser/parser_stream.js +0 -76
- package/lib/parser/plain_text_conversion_stream.js +0 -20
- package/lib/sax/dev_null_stream.js +0 -14
- package/lib/sax/index.js +0 -118
- package/lib/sax/parser_feedback_simulator.js +0 -153
- package/lib/serializer/serializer_stream.js +0 -28
- package/lib/tree_adapters/default.js +0 -209
- package/lib/tree_adapters/htmlparser2.js +0 -338
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Tokenizer = require('../tokenizer');
|
|
4
|
+
const HTML = require('./html');
|
|
5
|
+
|
|
6
|
+
//Aliases
|
|
7
|
+
const $ = HTML.TAG_NAMES;
|
|
8
|
+
const NS = HTML.NAMESPACES;
|
|
9
|
+
const ATTRS = HTML.ATTRS;
|
|
10
|
+
|
|
11
|
+
//MIME types
|
|
12
|
+
const MIME_TYPES = {
|
|
13
|
+
TEXT_HTML: 'text/html',
|
|
14
|
+
APPLICATION_XML: 'application/xhtml+xml'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//Attributes
|
|
18
|
+
const DEFINITION_URL_ATTR = 'definitionurl';
|
|
19
|
+
const ADJUSTED_DEFINITION_URL_ATTR = 'definitionURL';
|
|
20
|
+
const SVG_ATTRS_ADJUSTMENT_MAP = {
|
|
21
|
+
attributename: 'attributeName',
|
|
22
|
+
attributetype: 'attributeType',
|
|
23
|
+
basefrequency: 'baseFrequency',
|
|
24
|
+
baseprofile: 'baseProfile',
|
|
25
|
+
calcmode: 'calcMode',
|
|
26
|
+
clippathunits: 'clipPathUnits',
|
|
27
|
+
diffuseconstant: 'diffuseConstant',
|
|
28
|
+
edgemode: 'edgeMode',
|
|
29
|
+
filterunits: 'filterUnits',
|
|
30
|
+
glyphref: 'glyphRef',
|
|
31
|
+
gradienttransform: 'gradientTransform',
|
|
32
|
+
gradientunits: 'gradientUnits',
|
|
33
|
+
kernelmatrix: 'kernelMatrix',
|
|
34
|
+
kernelunitlength: 'kernelUnitLength',
|
|
35
|
+
keypoints: 'keyPoints',
|
|
36
|
+
keysplines: 'keySplines',
|
|
37
|
+
keytimes: 'keyTimes',
|
|
38
|
+
lengthadjust: 'lengthAdjust',
|
|
39
|
+
limitingconeangle: 'limitingConeAngle',
|
|
40
|
+
markerheight: 'markerHeight',
|
|
41
|
+
markerunits: 'markerUnits',
|
|
42
|
+
markerwidth: 'markerWidth',
|
|
43
|
+
maskcontentunits: 'maskContentUnits',
|
|
44
|
+
maskunits: 'maskUnits',
|
|
45
|
+
numoctaves: 'numOctaves',
|
|
46
|
+
pathlength: 'pathLength',
|
|
47
|
+
patterncontentunits: 'patternContentUnits',
|
|
48
|
+
patterntransform: 'patternTransform',
|
|
49
|
+
patternunits: 'patternUnits',
|
|
50
|
+
pointsatx: 'pointsAtX',
|
|
51
|
+
pointsaty: 'pointsAtY',
|
|
52
|
+
pointsatz: 'pointsAtZ',
|
|
53
|
+
preservealpha: 'preserveAlpha',
|
|
54
|
+
preserveaspectratio: 'preserveAspectRatio',
|
|
55
|
+
primitiveunits: 'primitiveUnits',
|
|
56
|
+
refx: 'refX',
|
|
57
|
+
refy: 'refY',
|
|
58
|
+
repeatcount: 'repeatCount',
|
|
59
|
+
repeatdur: 'repeatDur',
|
|
60
|
+
requiredextensions: 'requiredExtensions',
|
|
61
|
+
requiredfeatures: 'requiredFeatures',
|
|
62
|
+
specularconstant: 'specularConstant',
|
|
63
|
+
specularexponent: 'specularExponent',
|
|
64
|
+
spreadmethod: 'spreadMethod',
|
|
65
|
+
startoffset: 'startOffset',
|
|
66
|
+
stddeviation: 'stdDeviation',
|
|
67
|
+
stitchtiles: 'stitchTiles',
|
|
68
|
+
surfacescale: 'surfaceScale',
|
|
69
|
+
systemlanguage: 'systemLanguage',
|
|
70
|
+
tablevalues: 'tableValues',
|
|
71
|
+
targetx: 'targetX',
|
|
72
|
+
targety: 'targetY',
|
|
73
|
+
textlength: 'textLength',
|
|
74
|
+
viewbox: 'viewBox',
|
|
75
|
+
viewtarget: 'viewTarget',
|
|
76
|
+
xchannelselector: 'xChannelSelector',
|
|
77
|
+
ychannelselector: 'yChannelSelector',
|
|
78
|
+
zoomandpan: 'zoomAndPan'
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const 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
|
+
//SVG tag names adjustment map
|
|
97
|
+
const SVG_TAG_NAMES_ADJUSTMENT_MAP = (exports.SVG_TAG_NAMES_ADJUSTMENT_MAP = {
|
|
98
|
+
altglyph: 'altGlyph',
|
|
99
|
+
altglyphdef: 'altGlyphDef',
|
|
100
|
+
altglyphitem: 'altGlyphItem',
|
|
101
|
+
animatecolor: 'animateColor',
|
|
102
|
+
animatemotion: 'animateMotion',
|
|
103
|
+
animatetransform: 'animateTransform',
|
|
104
|
+
clippath: 'clipPath',
|
|
105
|
+
feblend: 'feBlend',
|
|
106
|
+
fecolormatrix: 'feColorMatrix',
|
|
107
|
+
fecomponenttransfer: 'feComponentTransfer',
|
|
108
|
+
fecomposite: 'feComposite',
|
|
109
|
+
feconvolvematrix: 'feConvolveMatrix',
|
|
110
|
+
fediffuselighting: 'feDiffuseLighting',
|
|
111
|
+
fedisplacementmap: 'feDisplacementMap',
|
|
112
|
+
fedistantlight: 'feDistantLight',
|
|
113
|
+
feflood: 'feFlood',
|
|
114
|
+
fefunca: 'feFuncA',
|
|
115
|
+
fefuncb: 'feFuncB',
|
|
116
|
+
fefuncg: 'feFuncG',
|
|
117
|
+
fefuncr: 'feFuncR',
|
|
118
|
+
fegaussianblur: 'feGaussianBlur',
|
|
119
|
+
feimage: 'feImage',
|
|
120
|
+
femerge: 'feMerge',
|
|
121
|
+
femergenode: 'feMergeNode',
|
|
122
|
+
femorphology: 'feMorphology',
|
|
123
|
+
feoffset: 'feOffset',
|
|
124
|
+
fepointlight: 'fePointLight',
|
|
125
|
+
fespecularlighting: 'feSpecularLighting',
|
|
126
|
+
fespotlight: 'feSpotLight',
|
|
127
|
+
fetile: 'feTile',
|
|
128
|
+
feturbulence: 'feTurbulence',
|
|
129
|
+
foreignobject: 'foreignObject',
|
|
130
|
+
glyphref: 'glyphRef',
|
|
131
|
+
lineargradient: 'linearGradient',
|
|
132
|
+
radialgradient: 'radialGradient',
|
|
133
|
+
textpath: 'textPath'
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
//Tags that causes exit from foreign content
|
|
137
|
+
const EXITS_FOREIGN_CONTENT = {
|
|
138
|
+
[$.B]: true,
|
|
139
|
+
[$.BIG]: true,
|
|
140
|
+
[$.BLOCKQUOTE]: true,
|
|
141
|
+
[$.BODY]: true,
|
|
142
|
+
[$.BR]: true,
|
|
143
|
+
[$.CENTER]: true,
|
|
144
|
+
[$.CODE]: true,
|
|
145
|
+
[$.DD]: true,
|
|
146
|
+
[$.DIV]: true,
|
|
147
|
+
[$.DL]: true,
|
|
148
|
+
[$.DT]: true,
|
|
149
|
+
[$.EM]: true,
|
|
150
|
+
[$.EMBED]: true,
|
|
151
|
+
[$.H1]: true,
|
|
152
|
+
[$.H2]: true,
|
|
153
|
+
[$.H3]: true,
|
|
154
|
+
[$.H4]: true,
|
|
155
|
+
[$.H5]: true,
|
|
156
|
+
[$.H6]: true,
|
|
157
|
+
[$.HEAD]: true,
|
|
158
|
+
[$.HR]: true,
|
|
159
|
+
[$.I]: true,
|
|
160
|
+
[$.IMG]: true,
|
|
161
|
+
[$.LI]: true,
|
|
162
|
+
[$.LISTING]: true,
|
|
163
|
+
[$.MENU]: true,
|
|
164
|
+
[$.META]: true,
|
|
165
|
+
[$.NOBR]: true,
|
|
166
|
+
[$.OL]: true,
|
|
167
|
+
[$.P]: true,
|
|
168
|
+
[$.PRE]: true,
|
|
169
|
+
[$.RUBY]: true,
|
|
170
|
+
[$.S]: true,
|
|
171
|
+
[$.SMALL]: true,
|
|
172
|
+
[$.SPAN]: true,
|
|
173
|
+
[$.STRONG]: true,
|
|
174
|
+
[$.STRIKE]: true,
|
|
175
|
+
[$.SUB]: true,
|
|
176
|
+
[$.SUP]: true,
|
|
177
|
+
[$.TABLE]: true,
|
|
178
|
+
[$.TT]: true,
|
|
179
|
+
[$.U]: true,
|
|
180
|
+
[$.UL]: true,
|
|
181
|
+
[$.VAR]: true
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
//Check exit from foreign content
|
|
185
|
+
exports.causesExit = function(startTagToken) {
|
|
186
|
+
const tn = startTagToken.tagName;
|
|
187
|
+
const isFontWithAttrs =
|
|
188
|
+
tn === $.FONT &&
|
|
189
|
+
(Tokenizer.getTokenAttr(startTagToken, ATTRS.COLOR) !== null ||
|
|
190
|
+
Tokenizer.getTokenAttr(startTagToken, ATTRS.SIZE) !== null ||
|
|
191
|
+
Tokenizer.getTokenAttr(startTagToken, ATTRS.FACE) !== null);
|
|
192
|
+
|
|
193
|
+
return isFontWithAttrs ? true : EXITS_FOREIGN_CONTENT[tn];
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
//Token adjustments
|
|
197
|
+
exports.adjustTokenMathMLAttrs = function(token) {
|
|
198
|
+
for (let i = 0; i < token.attrs.length; i++) {
|
|
199
|
+
if (token.attrs[i].name === DEFINITION_URL_ATTR) {
|
|
200
|
+
token.attrs[i].name = ADJUSTED_DEFINITION_URL_ATTR;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
exports.adjustTokenSVGAttrs = function(token) {
|
|
207
|
+
for (let i = 0; i < token.attrs.length; i++) {
|
|
208
|
+
const adjustedAttrName = SVG_ATTRS_ADJUSTMENT_MAP[token.attrs[i].name];
|
|
209
|
+
|
|
210
|
+
if (adjustedAttrName) {
|
|
211
|
+
token.attrs[i].name = adjustedAttrName;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
exports.adjustTokenXMLAttrs = function(token) {
|
|
217
|
+
for (let i = 0; i < token.attrs.length; i++) {
|
|
218
|
+
const adjustedAttrEntry = XML_ATTRS_ADJUSTMENT_MAP[token.attrs[i].name];
|
|
219
|
+
|
|
220
|
+
if (adjustedAttrEntry) {
|
|
221
|
+
token.attrs[i].prefix = adjustedAttrEntry.prefix;
|
|
222
|
+
token.attrs[i].name = adjustedAttrEntry.name;
|
|
223
|
+
token.attrs[i].namespace = adjustedAttrEntry.namespace;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
exports.adjustTokenSVGTagName = function(token) {
|
|
229
|
+
const adjustedTagName = SVG_TAG_NAMES_ADJUSTMENT_MAP[token.tagName];
|
|
230
|
+
|
|
231
|
+
if (adjustedTagName) {
|
|
232
|
+
token.tagName = adjustedTagName;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
//Integration points
|
|
237
|
+
function isMathMLTextIntegrationPoint(tn, ns) {
|
|
238
|
+
return ns === NS.MATHML && (tn === $.MI || tn === $.MO || tn === $.MN || tn === $.MS || tn === $.MTEXT);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function isHtmlIntegrationPoint(tn, ns, attrs) {
|
|
242
|
+
if (ns === NS.MATHML && tn === $.ANNOTATION_XML) {
|
|
243
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
244
|
+
if (attrs[i].name === ATTRS.ENCODING) {
|
|
245
|
+
const value = attrs[i].value.toLowerCase();
|
|
246
|
+
|
|
247
|
+
return value === MIME_TYPES.TEXT_HTML || value === MIME_TYPES.APPLICATION_XML;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return ns === NS.SVG && (tn === $.FOREIGN_OBJECT || tn === $.DESC || tn === $.TITLE);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
exports.isIntegrationPoint = function(tn, ns, attrs, foreignNS) {
|
|
256
|
+
if ((!foreignNS || foreignNS === NS.HTML) && isHtmlIntegrationPoint(tn, ns, attrs)) {
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if ((!foreignNS || foreignNS === NS.MATHML) && isMathMLTextIntegrationPoint(tn, ns)) {
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return false;
|
|
265
|
+
};
|
package/lib/common/html.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const NS = (exports.NAMESPACES = {
|
|
4
4
|
HTML: 'http://www.w3.org/1999/xhtml',
|
|
5
5
|
MATHML: 'http://www.w3.org/1998/Math/MathML',
|
|
6
6
|
SVG: 'http://www.w3.org/2000/svg',
|
|
7
7
|
XLINK: 'http://www.w3.org/1999/xlink',
|
|
8
8
|
XML: 'http://www.w3.org/XML/1998/namespace',
|
|
9
9
|
XMLNS: 'http://www.w3.org/2000/xmlns/'
|
|
10
|
-
};
|
|
10
|
+
});
|
|
11
11
|
|
|
12
12
|
exports.ATTRS = {
|
|
13
13
|
TYPE: 'type',
|
|
@@ -26,7 +26,7 @@ exports.DOCUMENT_MODE = {
|
|
|
26
26
|
LIMITED_QUIRKS: 'limited-quirks'
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
const $ = (exports.TAG_NAMES = {
|
|
30
30
|
A: 'a',
|
|
31
31
|
ADDRESS: 'address',
|
|
32
32
|
ANNOTATION_XML: 'annotation-xml',
|
|
@@ -103,7 +103,6 @@ var $ = exports.TAG_NAMES = {
|
|
|
103
103
|
MARQUEE: 'marquee',
|
|
104
104
|
MATH: 'math',
|
|
105
105
|
MENU: 'menu',
|
|
106
|
-
MENUITEM: 'menuitem',
|
|
107
106
|
META: 'meta',
|
|
108
107
|
MGLYPH: 'mglyph',
|
|
109
108
|
MI: 'mi',
|
|
@@ -171,102 +170,103 @@ var $ = exports.TAG_NAMES = {
|
|
|
171
170
|
WBR: 'wbr',
|
|
172
171
|
|
|
173
172
|
XMP: 'xmp'
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
var SPECIAL_ELEMENTS = exports.SPECIAL_ELEMENTS = Object.create(null);
|
|
173
|
+
});
|
|
177
174
|
|
|
178
|
-
SPECIAL_ELEMENTS
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
175
|
+
exports.SPECIAL_ELEMENTS = {
|
|
176
|
+
[NS.HTML]: {
|
|
177
|
+
[$.ADDRESS]: true,
|
|
178
|
+
[$.APPLET]: true,
|
|
179
|
+
[$.AREA]: true,
|
|
180
|
+
[$.ARTICLE]: true,
|
|
181
|
+
[$.ASIDE]: true,
|
|
182
|
+
[$.BASE]: true,
|
|
183
|
+
[$.BASEFONT]: true,
|
|
184
|
+
[$.BGSOUND]: true,
|
|
185
|
+
[$.BLOCKQUOTE]: true,
|
|
186
|
+
[$.BODY]: true,
|
|
187
|
+
[$.BR]: true,
|
|
188
|
+
[$.BUTTON]: true,
|
|
189
|
+
[$.CAPTION]: true,
|
|
190
|
+
[$.CENTER]: true,
|
|
191
|
+
[$.COL]: true,
|
|
192
|
+
[$.COLGROUP]: true,
|
|
193
|
+
[$.DD]: true,
|
|
194
|
+
[$.DETAILS]: true,
|
|
195
|
+
[$.DIR]: true,
|
|
196
|
+
[$.DIV]: true,
|
|
197
|
+
[$.DL]: true,
|
|
198
|
+
[$.DT]: true,
|
|
199
|
+
[$.EMBED]: true,
|
|
200
|
+
[$.FIELDSET]: true,
|
|
201
|
+
[$.FIGCAPTION]: true,
|
|
202
|
+
[$.FIGURE]: true,
|
|
203
|
+
[$.FOOTER]: true,
|
|
204
|
+
[$.FORM]: true,
|
|
205
|
+
[$.FRAME]: true,
|
|
206
|
+
[$.FRAMESET]: true,
|
|
207
|
+
[$.H1]: true,
|
|
208
|
+
[$.H2]: true,
|
|
209
|
+
[$.H3]: true,
|
|
210
|
+
[$.H4]: true,
|
|
211
|
+
[$.H5]: true,
|
|
212
|
+
[$.H6]: true,
|
|
213
|
+
[$.HEAD]: true,
|
|
214
|
+
[$.HEADER]: true,
|
|
215
|
+
[$.HGROUP]: true,
|
|
216
|
+
[$.HR]: true,
|
|
217
|
+
[$.HTML]: true,
|
|
218
|
+
[$.IFRAME]: true,
|
|
219
|
+
[$.IMG]: true,
|
|
220
|
+
[$.INPUT]: true,
|
|
221
|
+
[$.LI]: true,
|
|
222
|
+
[$.LINK]: true,
|
|
223
|
+
[$.LISTING]: true,
|
|
224
|
+
[$.MAIN]: true,
|
|
225
|
+
[$.MARQUEE]: true,
|
|
226
|
+
[$.MENU]: true,
|
|
227
|
+
[$.META]: true,
|
|
228
|
+
[$.NAV]: true,
|
|
229
|
+
[$.NOEMBED]: true,
|
|
230
|
+
[$.NOFRAMES]: true,
|
|
231
|
+
[$.NOSCRIPT]: true,
|
|
232
|
+
[$.OBJECT]: true,
|
|
233
|
+
[$.OL]: true,
|
|
234
|
+
[$.P]: true,
|
|
235
|
+
[$.PARAM]: true,
|
|
236
|
+
[$.PLAINTEXT]: true,
|
|
237
|
+
[$.PRE]: true,
|
|
238
|
+
[$.SCRIPT]: true,
|
|
239
|
+
[$.SECTION]: true,
|
|
240
|
+
[$.SELECT]: true,
|
|
241
|
+
[$.SOURCE]: true,
|
|
242
|
+
[$.STYLE]: true,
|
|
243
|
+
[$.SUMMARY]: true,
|
|
244
|
+
[$.TABLE]: true,
|
|
245
|
+
[$.TBODY]: true,
|
|
246
|
+
[$.TD]: true,
|
|
247
|
+
[$.TEMPLATE]: true,
|
|
248
|
+
[$.TEXTAREA]: true,
|
|
249
|
+
[$.TFOOT]: true,
|
|
250
|
+
[$.TH]: true,
|
|
251
|
+
[$.THEAD]: true,
|
|
252
|
+
[$.TITLE]: true,
|
|
253
|
+
[$.TR]: true,
|
|
254
|
+
[$.TRACK]: true,
|
|
255
|
+
[$.UL]: true,
|
|
256
|
+
[$.WBR]: true,
|
|
257
|
+
[$.XMP]: true
|
|
258
|
+
},
|
|
259
|
+
[NS.MATHML]: {
|
|
260
|
+
[$.MI]: true,
|
|
261
|
+
[$.MO]: true,
|
|
262
|
+
[$.MN]: true,
|
|
263
|
+
[$.MS]: true,
|
|
264
|
+
[$.MTEXT]: true,
|
|
265
|
+
[$.ANNOTATION_XML]: true
|
|
266
|
+
},
|
|
267
|
+
[NS.SVG]: {
|
|
268
|
+
[$.TITLE]: true,
|
|
269
|
+
[$.FOREIGN_OBJECT]: true,
|
|
270
|
+
[$.DESC]: true
|
|
271
|
+
}
|
|
272
|
+
};
|
package/lib/common/unicode.js
CHANGED
|
@@ -1,47 +1,109 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const UNDEFINED_CODE_POINTS = [
|
|
4
|
+
0xfffe,
|
|
5
|
+
0xffff,
|
|
6
|
+
0x1fffe,
|
|
7
|
+
0x1ffff,
|
|
8
|
+
0x2fffe,
|
|
9
|
+
0x2ffff,
|
|
10
|
+
0x3fffe,
|
|
11
|
+
0x3ffff,
|
|
12
|
+
0x4fffe,
|
|
13
|
+
0x4ffff,
|
|
14
|
+
0x5fffe,
|
|
15
|
+
0x5ffff,
|
|
16
|
+
0x6fffe,
|
|
17
|
+
0x6ffff,
|
|
18
|
+
0x7fffe,
|
|
19
|
+
0x7ffff,
|
|
20
|
+
0x8fffe,
|
|
21
|
+
0x8ffff,
|
|
22
|
+
0x9fffe,
|
|
23
|
+
0x9ffff,
|
|
24
|
+
0xafffe,
|
|
25
|
+
0xaffff,
|
|
26
|
+
0xbfffe,
|
|
27
|
+
0xbffff,
|
|
28
|
+
0xcfffe,
|
|
29
|
+
0xcffff,
|
|
30
|
+
0xdfffe,
|
|
31
|
+
0xdffff,
|
|
32
|
+
0xefffe,
|
|
33
|
+
0xeffff,
|
|
34
|
+
0xffffe,
|
|
35
|
+
0xfffff,
|
|
36
|
+
0x10fffe,
|
|
37
|
+
0x10ffff
|
|
38
|
+
];
|
|
39
|
+
|
|
3
40
|
exports.REPLACEMENT_CHARACTER = '\uFFFD';
|
|
4
41
|
|
|
5
42
|
exports.CODE_POINTS = {
|
|
6
43
|
EOF: -1,
|
|
7
44
|
NULL: 0x00,
|
|
8
45
|
TABULATION: 0x09,
|
|
9
|
-
CARRIAGE_RETURN:
|
|
10
|
-
LINE_FEED:
|
|
11
|
-
FORM_FEED:
|
|
46
|
+
CARRIAGE_RETURN: 0x0d,
|
|
47
|
+
LINE_FEED: 0x0a,
|
|
48
|
+
FORM_FEED: 0x0c,
|
|
12
49
|
SPACE: 0x20,
|
|
13
50
|
EXCLAMATION_MARK: 0x21,
|
|
14
51
|
QUOTATION_MARK: 0x22,
|
|
15
52
|
NUMBER_SIGN: 0x23,
|
|
16
53
|
AMPERSAND: 0x26,
|
|
17
54
|
APOSTROPHE: 0x27,
|
|
18
|
-
HYPHEN_MINUS:
|
|
19
|
-
SOLIDUS:
|
|
55
|
+
HYPHEN_MINUS: 0x2d,
|
|
56
|
+
SOLIDUS: 0x2f,
|
|
20
57
|
DIGIT_0: 0x30,
|
|
21
58
|
DIGIT_9: 0x39,
|
|
22
|
-
SEMICOLON:
|
|
23
|
-
LESS_THAN_SIGN:
|
|
24
|
-
EQUALS_SIGN:
|
|
25
|
-
GREATER_THAN_SIGN:
|
|
26
|
-
QUESTION_MARK:
|
|
59
|
+
SEMICOLON: 0x3b,
|
|
60
|
+
LESS_THAN_SIGN: 0x3c,
|
|
61
|
+
EQUALS_SIGN: 0x3d,
|
|
62
|
+
GREATER_THAN_SIGN: 0x3e,
|
|
63
|
+
QUESTION_MARK: 0x3f,
|
|
27
64
|
LATIN_CAPITAL_A: 0x41,
|
|
28
65
|
LATIN_CAPITAL_F: 0x46,
|
|
29
66
|
LATIN_CAPITAL_X: 0x58,
|
|
30
|
-
LATIN_CAPITAL_Z:
|
|
67
|
+
LATIN_CAPITAL_Z: 0x5a,
|
|
68
|
+
RIGHT_SQUARE_BRACKET: 0x5d,
|
|
31
69
|
GRAVE_ACCENT: 0x60,
|
|
32
70
|
LATIN_SMALL_A: 0x61,
|
|
33
71
|
LATIN_SMALL_F: 0x66,
|
|
34
72
|
LATIN_SMALL_X: 0x78,
|
|
35
|
-
LATIN_SMALL_Z:
|
|
36
|
-
REPLACEMENT_CHARACTER:
|
|
73
|
+
LATIN_SMALL_Z: 0x7a,
|
|
74
|
+
REPLACEMENT_CHARACTER: 0xfffd
|
|
37
75
|
};
|
|
38
76
|
|
|
39
77
|
exports.CODE_POINT_SEQUENCES = {
|
|
40
|
-
DASH_DASH_STRING: [
|
|
41
|
-
DOCTYPE_STRING: [0x44,
|
|
42
|
-
CDATA_START_STRING: [
|
|
43
|
-
CDATA_END_STRING: [0x5D, 0x5D, 0x3E], //]]>
|
|
78
|
+
DASH_DASH_STRING: [0x2d, 0x2d], //--
|
|
79
|
+
DOCTYPE_STRING: [0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45], //DOCTYPE
|
|
80
|
+
CDATA_START_STRING: [0x5b, 0x43, 0x44, 0x41, 0x54, 0x41, 0x5b], //[CDATA[
|
|
44
81
|
SCRIPT_STRING: [0x73, 0x63, 0x72, 0x69, 0x70, 0x74], //script
|
|
45
|
-
PUBLIC_STRING: [0x50, 0x55, 0x42,
|
|
46
|
-
SYSTEM_STRING: [0x53, 0x59, 0x53, 0x54, 0x45,
|
|
82
|
+
PUBLIC_STRING: [0x50, 0x55, 0x42, 0x4c, 0x49, 0x43], //PUBLIC
|
|
83
|
+
SYSTEM_STRING: [0x53, 0x59, 0x53, 0x54, 0x45, 0x4d] //SYSTEM
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
//Surrogates
|
|
87
|
+
exports.isSurrogate = function(cp) {
|
|
88
|
+
return cp >= 0xd800 && cp <= 0xdfff;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
exports.isSurrogatePair = function(cp) {
|
|
92
|
+
return cp >= 0xdc00 && cp <= 0xdfff;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
exports.getSurrogatePairCodePoint = function(cp1, cp2) {
|
|
96
|
+
return (cp1 - 0xd800) * 0x400 + 0x2400 + cp2;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
//NOTE: excluding NULL and ASCII whitespace
|
|
100
|
+
exports.isControlCodePoint = function(cp) {
|
|
101
|
+
return (
|
|
102
|
+
(cp !== 0x20 && cp !== 0x0a && cp !== 0x0d && cp !== 0x09 && cp !== 0x0c && cp >= 0x01 && cp <= 0x1f) ||
|
|
103
|
+
(cp >= 0x7f && cp <= 0x9f)
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
exports.isUndefinedCodePoint = function(cp) {
|
|
108
|
+
return (cp >= 0xfdd0 && cp <= 0xfdef) || UNDEFINED_CODE_POINTS.indexOf(cp) > -1;
|
|
47
109
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Mixin = require('../../utils/mixin');
|
|
4
|
+
|
|
5
|
+
class ErrorReportingMixinBase extends Mixin {
|
|
6
|
+
constructor(host, opts) {
|
|
7
|
+
super(host);
|
|
8
|
+
|
|
9
|
+
this.posTracker = null;
|
|
10
|
+
this.onParseError = opts.onParseError;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
_setErrorLocation(err) {
|
|
14
|
+
err.startLine = err.endLine = this.posTracker.line;
|
|
15
|
+
err.startCol = err.endCol = this.posTracker.col;
|
|
16
|
+
err.startOffset = err.endOffset = this.posTracker.offset;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_reportError(code) {
|
|
20
|
+
const err = {
|
|
21
|
+
code: code,
|
|
22
|
+
startLine: -1,
|
|
23
|
+
startCol: -1,
|
|
24
|
+
startOffset: -1,
|
|
25
|
+
endLine: -1,
|
|
26
|
+
endCol: -1,
|
|
27
|
+
endOffset: -1
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
this._setErrorLocation(err);
|
|
31
|
+
this.onParseError(err);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_getOverriddenMethods(mxn) {
|
|
35
|
+
return {
|
|
36
|
+
_err(code) {
|
|
37
|
+
mxn._reportError(code);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = ErrorReportingMixinBase;
|