@loaders.gl/xml 3.4.14 → 3.4.15
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/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/html-loader.js +6 -29
- package/dist/es5/html-loader.js.map +1 -1
- package/dist/es5/index.js +7 -7
- package/dist/es5/lib/parsers/parse-xml.js +9 -11
- package/dist/es5/lib/parsers/parse-xml.js.map +1 -1
- package/dist/es5/lib/parsers/streaming-xml-parser.js +83 -103
- package/dist/es5/lib/parsers/streaming-xml-parser.js.map +1 -1
- package/dist/es5/lib/xml-utils/uncapitalize.js +4 -12
- package/dist/es5/lib/xml-utils/uncapitalize.js.map +1 -1
- package/dist/es5/lib/xml-utils/xml-utils.js +1 -3
- package/dist/es5/lib/xml-utils/xml-utils.js.map +1 -1
- package/dist/es5/sax-ts/sax.js +834 -904
- package/dist/es5/sax-ts/sax.js.map +1 -1
- package/dist/es5/xml-loader.js +17 -39
- package/dist/es5/xml-loader.js.map +1 -1
- package/dist/esm/xml-loader.js +1 -1
- package/package.json +4 -4
package/dist/es5/sax-ts/sax.js
CHANGED
|
@@ -5,39 +5,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.SAXParser = exports.ENTITIES = void 0;
|
|
8
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
9
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
10
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
11
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
12
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
13
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
onready: function onready() {},
|
|
36
|
-
onscript: function onscript() {},
|
|
37
|
-
onopennamespace: function onopennamespace() {},
|
|
38
|
-
onclosenamespace: function onclosenamespace() {}
|
|
9
|
+
const DEFAULT_SAX_EVENTS = {
|
|
10
|
+
ontext: () => {},
|
|
11
|
+
onprocessinginstruction: () => {},
|
|
12
|
+
onsgmldeclaration: () => {},
|
|
13
|
+
ondoctype: () => {},
|
|
14
|
+
oncomment: () => {},
|
|
15
|
+
onopentagstart: () => {},
|
|
16
|
+
onattribute: () => {},
|
|
17
|
+
onopentag: () => {},
|
|
18
|
+
onclosetag: () => {},
|
|
19
|
+
onopencdata: () => {},
|
|
20
|
+
oncdata: () => {},
|
|
21
|
+
onclosecdata: () => {},
|
|
22
|
+
onerror: () => {},
|
|
23
|
+
onend: () => {},
|
|
24
|
+
onready: () => {},
|
|
25
|
+
onscript: () => {},
|
|
26
|
+
onopennamespace: () => {},
|
|
27
|
+
onclosenamespace: () => {}
|
|
39
28
|
};
|
|
40
|
-
|
|
29
|
+
const DEFAULT_SAX_PARSER_OPTIONS = {
|
|
30
|
+
...DEFAULT_SAX_EVENTS,
|
|
41
31
|
strict: false,
|
|
42
32
|
MAX_BUFFER_LENGTH: 64 * 1024,
|
|
43
33
|
lowercase: false,
|
|
@@ -48,14 +38,14 @@ var DEFAULT_SAX_PARSER_OPTIONS = _objectSpread(_objectSpread({}, DEFAULT_SAX_EVE
|
|
|
48
38
|
position: undefined,
|
|
49
39
|
trim: undefined,
|
|
50
40
|
normalize: undefined
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
41
|
+
};
|
|
42
|
+
const EVENTS = ['text', 'processinginstruction', 'sgmldeclaration', 'doctype', 'comment', 'opentagstart', 'attribute', 'opentag', 'closetag', 'opencdata', 'cdata', 'closecdata', 'error', 'end', 'ready', 'script', 'opennamespace', 'closenamespace'];
|
|
43
|
+
const BUFFERS = ['comment', 'sgmlDecl', 'textNode', 'tagName', 'doctype', 'procInstName', 'procInstBody', 'entity', 'attribName', 'attribValue', 'cdata', 'script'];
|
|
44
|
+
const nameStart = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;
|
|
45
|
+
const nameBody = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/;
|
|
46
|
+
const entityStart = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;
|
|
47
|
+
const entityBody = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/;
|
|
48
|
+
const ENTITIES = {
|
|
59
49
|
amp: '&',
|
|
60
50
|
gt: '>',
|
|
61
51
|
lt: '<',
|
|
@@ -311,15 +301,16 @@ var ENTITIES = {
|
|
|
311
301
|
diams: 9830
|
|
312
302
|
};
|
|
313
303
|
exports.ENTITIES = ENTITIES;
|
|
314
|
-
Object.keys(ENTITIES).forEach(
|
|
315
|
-
|
|
304
|
+
Object.keys(ENTITIES).forEach(key => {
|
|
305
|
+
const e = ENTITIES[key];
|
|
316
306
|
ENTITIES[key] = typeof e === 'number' ? String.fromCharCode(e) : e;
|
|
317
307
|
});
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
(0, _classCallCheck2.default)(this, SAX);
|
|
308
|
+
class SAX {
|
|
309
|
+
constructor() {
|
|
321
310
|
(0, _defineProperty2.default)(this, "EVENTS", EVENTS);
|
|
322
|
-
(0, _defineProperty2.default)(this, "ENTITIES",
|
|
311
|
+
(0, _defineProperty2.default)(this, "ENTITIES", {
|
|
312
|
+
...ENTITIES
|
|
313
|
+
});
|
|
323
314
|
(0, _defineProperty2.default)(this, "events", void 0);
|
|
324
315
|
(0, _defineProperty2.default)(this, "XML_ENTITIES", {
|
|
325
316
|
amp: '&',
|
|
@@ -411,962 +402,901 @@ var SAX = function () {
|
|
|
411
402
|
(0, _defineProperty2.default)(this, "script", '');
|
|
412
403
|
(0, _defineProperty2.default)(this, "startTagPosition", 0);
|
|
413
404
|
this.S = 0;
|
|
414
|
-
for (
|
|
405
|
+
for (const s in this.STATE) {
|
|
415
406
|
if (this.STATE.hasOwnProperty(s)) {
|
|
416
407
|
this.STATE[this.STATE[s]] = s;
|
|
417
408
|
}
|
|
418
409
|
}
|
|
419
410
|
this.S = this.STATE;
|
|
420
411
|
}
|
|
421
|
-
(
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
412
|
+
static charAt(chunk, i) {
|
|
413
|
+
let result = '';
|
|
414
|
+
if (i < chunk.length) {
|
|
415
|
+
result = chunk.charAt(i);
|
|
416
|
+
}
|
|
417
|
+
return result;
|
|
418
|
+
}
|
|
419
|
+
static isWhitespace(c) {
|
|
420
|
+
return c === ' ' || c === '\n' || c === '\r' || c === '\t';
|
|
421
|
+
}
|
|
422
|
+
static isQuote(c) {
|
|
423
|
+
return c === '"' || c === "'";
|
|
424
|
+
}
|
|
425
|
+
static isAttribEnd(c) {
|
|
426
|
+
return c === '>' || SAX.isWhitespace(c);
|
|
427
|
+
}
|
|
428
|
+
static isMatch(regex, c) {
|
|
429
|
+
return regex.test(c);
|
|
430
|
+
}
|
|
431
|
+
static notMatch(regex, c) {
|
|
432
|
+
return !SAX.isMatch(regex, c);
|
|
433
|
+
}
|
|
434
|
+
static qname(name, attribute) {
|
|
435
|
+
const i = name.indexOf(':');
|
|
436
|
+
const qualName = i < 0 ? ['', name] : name.split(':');
|
|
437
|
+
let prefix = qualName[0];
|
|
438
|
+
let local = qualName[1];
|
|
439
|
+
if (attribute && name === 'xmlns') {
|
|
440
|
+
prefix = 'xmlns';
|
|
441
|
+
local = '';
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
prefix,
|
|
445
|
+
local
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
write(chunk) {
|
|
449
|
+
if (this.error) {
|
|
450
|
+
throw this.error;
|
|
451
|
+
}
|
|
452
|
+
if (this.closed) {
|
|
453
|
+
return this.errorFunction('Cannot write after close. Assign an onready handler.');
|
|
454
|
+
}
|
|
455
|
+
if (chunk === null) {
|
|
456
|
+
return this.end();
|
|
457
|
+
}
|
|
458
|
+
if (typeof chunk === 'object') {
|
|
459
|
+
chunk = chunk.toString();
|
|
460
|
+
}
|
|
461
|
+
let i = 0;
|
|
462
|
+
let c;
|
|
463
|
+
while (true) {
|
|
464
|
+
c = SAX.charAt(chunk, i++);
|
|
465
|
+
this.c = c;
|
|
466
|
+
if (!c) {
|
|
467
|
+
break;
|
|
435
468
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
if (this.trackPosition) {
|
|
445
|
-
this.position++;
|
|
446
|
-
if (c === '\n') {
|
|
447
|
-
this.line++;
|
|
448
|
-
this.column = 0;
|
|
449
|
-
} else {
|
|
450
|
-
this.column++;
|
|
451
|
-
}
|
|
469
|
+
if (this.trackPosition) {
|
|
470
|
+
this.position++;
|
|
471
|
+
if (c === '\n') {
|
|
472
|
+
this.line++;
|
|
473
|
+
this.column = 0;
|
|
474
|
+
} else {
|
|
475
|
+
this.column++;
|
|
452
476
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
this.beginWhiteSpace(c);
|
|
460
|
-
continue;
|
|
461
|
-
case this.S.BEGIN_WHITESPACE:
|
|
462
|
-
this.beginWhiteSpace(c);
|
|
477
|
+
}
|
|
478
|
+
switch (this.state) {
|
|
479
|
+
case this.S.BEGIN:
|
|
480
|
+
this.state = this.S.BEGIN_WHITESPACE;
|
|
481
|
+
if (c === '\uFEFF') {
|
|
463
482
|
continue;
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
483
|
+
}
|
|
484
|
+
this.beginWhiteSpace(c);
|
|
485
|
+
continue;
|
|
486
|
+
case this.S.BEGIN_WHITESPACE:
|
|
487
|
+
this.beginWhiteSpace(c);
|
|
488
|
+
continue;
|
|
489
|
+
case this.S.TEXT:
|
|
490
|
+
if (this.sawRoot && !this.closedRoot) {
|
|
491
|
+
const starti = i - 1;
|
|
492
|
+
while (c && c !== '<' && c !== '&') {
|
|
493
|
+
c = SAX.charAt(chunk, i++);
|
|
494
|
+
if (c && this.trackPosition) {
|
|
495
|
+
this.position++;
|
|
496
|
+
if (c === '\n') {
|
|
497
|
+
this.line++;
|
|
498
|
+
this.column = 0;
|
|
499
|
+
} else {
|
|
500
|
+
this.column++;
|
|
477
501
|
}
|
|
478
502
|
}
|
|
479
|
-
this.textNode += chunk.substring(starti, i - 1);
|
|
480
503
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
this.state = this.S.TEXT_ENTITY;
|
|
490
|
-
} else {
|
|
491
|
-
this.textNode += c;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
continue;
|
|
495
|
-
case this.S.SCRIPT:
|
|
496
|
-
if (c === '<') {
|
|
497
|
-
this.state = this.S.SCRIPT_ENDING;
|
|
498
|
-
} else {
|
|
499
|
-
this.script += c;
|
|
500
|
-
}
|
|
501
|
-
continue;
|
|
502
|
-
case this.S.SCRIPT_ENDING:
|
|
503
|
-
if (c === '/') {
|
|
504
|
-
this.state = this.S.CLOSE_TAG;
|
|
505
|
-
} else {
|
|
506
|
-
this.script += "<".concat(c);
|
|
507
|
-
this.state = this.S.SCRIPT;
|
|
504
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
505
|
+
}
|
|
506
|
+
if (c === '<' && !(this.sawRoot && this.closedRoot && !this.strict)) {
|
|
507
|
+
this.state = this.S.OPEN_WAKA;
|
|
508
|
+
this.startTagPosition = this.position;
|
|
509
|
+
} else {
|
|
510
|
+
if (!SAX.isWhitespace(c) && (!this.sawRoot || this.closedRoot)) {
|
|
511
|
+
this.strictFail('Text data outside of root node.');
|
|
508
512
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
if (c === '!') {
|
|
512
|
-
this.state = this.S.SGML_DECL;
|
|
513
|
-
this.sgmlDecl = '';
|
|
514
|
-
} else if (SAX.isWhitespace(c)) {} else if (SAX.isMatch(nameStart, c)) {
|
|
515
|
-
this.state = this.S.OPEN_TAG;
|
|
516
|
-
this.tagName = c;
|
|
517
|
-
} else if (c === '/') {
|
|
518
|
-
this.state = this.S.CLOSE_TAG;
|
|
519
|
-
this.tagName = '';
|
|
520
|
-
} else if (c === '?') {
|
|
521
|
-
this.state = this.S.PROC_INST;
|
|
522
|
-
this.procInstName = this.procInstBody = '';
|
|
513
|
+
if (c === '&') {
|
|
514
|
+
this.state = this.S.TEXT_ENTITY;
|
|
523
515
|
} else {
|
|
524
|
-
this.
|
|
525
|
-
if (this.startTagPosition + 1 < this.position) {
|
|
526
|
-
var pad = this.position - this.startTagPosition;
|
|
527
|
-
c = new Array(pad).join(' ') + c;
|
|
528
|
-
}
|
|
529
|
-
this.textNode += "<".concat(c);
|
|
530
|
-
this.state = this.S.TEXT;
|
|
516
|
+
this.textNode += c;
|
|
531
517
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
518
|
+
}
|
|
519
|
+
continue;
|
|
520
|
+
case this.S.SCRIPT:
|
|
521
|
+
if (c === '<') {
|
|
522
|
+
this.state = this.S.SCRIPT_ENDING;
|
|
523
|
+
} else {
|
|
524
|
+
this.script += c;
|
|
525
|
+
}
|
|
526
|
+
continue;
|
|
527
|
+
case this.S.SCRIPT_ENDING:
|
|
528
|
+
if (c === '/') {
|
|
529
|
+
this.state = this.S.CLOSE_TAG;
|
|
530
|
+
} else {
|
|
531
|
+
this.script += "<".concat(c);
|
|
532
|
+
this.state = this.S.SCRIPT;
|
|
533
|
+
}
|
|
534
|
+
continue;
|
|
535
|
+
case this.S.OPEN_WAKA:
|
|
536
|
+
if (c === '!') {
|
|
537
|
+
this.state = this.S.SGML_DECL;
|
|
538
|
+
this.sgmlDecl = '';
|
|
539
|
+
} else if (SAX.isWhitespace(c)) {} else if (SAX.isMatch(nameStart, c)) {
|
|
540
|
+
this.state = this.S.OPEN_TAG;
|
|
541
|
+
this.tagName = c;
|
|
542
|
+
} else if (c === '/') {
|
|
543
|
+
this.state = this.S.CLOSE_TAG;
|
|
544
|
+
this.tagName = '';
|
|
545
|
+
} else if (c === '?') {
|
|
546
|
+
this.state = this.S.PROC_INST;
|
|
547
|
+
this.procInstName = this.procInstBody = '';
|
|
548
|
+
} else {
|
|
549
|
+
this.strictFail('Unencoded <');
|
|
550
|
+
if (this.startTagPosition + 1 < this.position) {
|
|
551
|
+
const pad = this.position - this.startTagPosition;
|
|
552
|
+
c = new Array(pad).join(' ') + c;
|
|
559
553
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
554
|
+
this.textNode += "<".concat(c);
|
|
555
|
+
this.state = this.S.TEXT;
|
|
556
|
+
}
|
|
557
|
+
continue;
|
|
558
|
+
case this.S.SGML_DECL:
|
|
559
|
+
if ((this.sgmlDecl + c).toUpperCase() === this.CDATA) {
|
|
560
|
+
this.emitNode('onopencdata');
|
|
561
|
+
this.state = this.S.CDATA;
|
|
562
|
+
this.sgmlDecl = '';
|
|
563
|
+
this.cdata = '';
|
|
564
|
+
} else if (this.sgmlDecl + c === '--') {
|
|
565
|
+
this.state = this.S.COMMENT;
|
|
566
|
+
this.comment = '';
|
|
567
|
+
this.sgmlDecl = '';
|
|
568
|
+
} else if ((this.sgmlDecl + c).toUpperCase() === this.DOCTYPE) {
|
|
569
|
+
this.state = this.S.DOCTYPE;
|
|
570
|
+
if (this.doctype || this.sawRoot) {
|
|
571
|
+
this.strictFail('Inappropriately located doctype declaration');
|
|
565
572
|
}
|
|
573
|
+
this.doctype = '';
|
|
574
|
+
this.sgmlDecl = '';
|
|
575
|
+
} else if (c === '>') {
|
|
576
|
+
this.emitNode('onsgmldeclaration', this.sgmlDecl);
|
|
577
|
+
this.sgmlDecl = '';
|
|
578
|
+
this.state = this.S.TEXT;
|
|
579
|
+
} else if (SAX.isQuote(c)) {
|
|
580
|
+
this.state = this.S.SGML_DECL_QUOTED;
|
|
566
581
|
this.sgmlDecl += c;
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
this.doctype += c;
|
|
585
|
-
if (c === this.q) {
|
|
586
|
-
this.q = '';
|
|
587
|
-
this.state = this.S.DOCTYPE;
|
|
588
|
-
}
|
|
589
|
-
continue;
|
|
590
|
-
case this.S.DOCTYPE_DTD:
|
|
582
|
+
} else {
|
|
583
|
+
this.sgmlDecl += c;
|
|
584
|
+
}
|
|
585
|
+
continue;
|
|
586
|
+
case this.S.SGML_DECL_QUOTED:
|
|
587
|
+
if (c === this.q) {
|
|
588
|
+
this.state = this.S.SGML_DECL;
|
|
589
|
+
this.q = '';
|
|
590
|
+
}
|
|
591
|
+
this.sgmlDecl += c;
|
|
592
|
+
continue;
|
|
593
|
+
case this.S.DOCTYPE:
|
|
594
|
+
if (c === '>') {
|
|
595
|
+
this.state = this.S.TEXT;
|
|
596
|
+
this.emitNode('ondoctype', this.doctype);
|
|
597
|
+
this.doctype = true;
|
|
598
|
+
} else {
|
|
591
599
|
this.doctype += c;
|
|
592
|
-
if (c === '
|
|
593
|
-
this.state = this.S.
|
|
600
|
+
if (c === '[') {
|
|
601
|
+
this.state = this.S.DOCTYPE_DTD;
|
|
594
602
|
} else if (SAX.isQuote(c)) {
|
|
595
|
-
this.state = this.S.
|
|
603
|
+
this.state = this.S.DOCTYPE_QUOTED;
|
|
596
604
|
this.q = c;
|
|
597
605
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
if (c === ']') {
|
|
637
|
-
this.state = this.S.CDATA_ENDING;
|
|
638
|
-
} else {
|
|
639
|
-
this.cdata += c;
|
|
640
|
-
}
|
|
641
|
-
continue;
|
|
642
|
-
case this.S.CDATA_ENDING:
|
|
643
|
-
if (c === ']') {
|
|
644
|
-
this.state = this.S.CDATA_ENDING_2;
|
|
645
|
-
} else {
|
|
646
|
-
this.cdata += "]".concat(c);
|
|
647
|
-
this.state = this.S.CDATA;
|
|
648
|
-
}
|
|
649
|
-
continue;
|
|
650
|
-
case this.S.CDATA_ENDING_2:
|
|
651
|
-
if (c === '>') {
|
|
652
|
-
if (this.cdata) {
|
|
653
|
-
this.emitNode('oncdata', this.cdata);
|
|
654
|
-
}
|
|
655
|
-
this.emitNode('onclosecdata');
|
|
656
|
-
this.cdata = '';
|
|
657
|
-
this.state = this.S.TEXT;
|
|
658
|
-
} else if (c === ']') {
|
|
659
|
-
this.cdata += ']';
|
|
660
|
-
} else {
|
|
661
|
-
this.cdata += "]]".concat(c);
|
|
662
|
-
this.state = this.S.CDATA;
|
|
663
|
-
}
|
|
664
|
-
continue;
|
|
665
|
-
case this.S.PROC_INST:
|
|
666
|
-
if (c === '?') {
|
|
667
|
-
this.state = this.S.PROC_INST_ENDING;
|
|
668
|
-
} else if (SAX.isWhitespace(c)) {
|
|
669
|
-
this.state = this.S.PROC_INST_BODY;
|
|
670
|
-
} else {
|
|
671
|
-
this.procInstName += c;
|
|
672
|
-
}
|
|
673
|
-
continue;
|
|
674
|
-
case this.S.PROC_INST_BODY:
|
|
675
|
-
if (!this.procInstBody && SAX.isWhitespace(c)) {
|
|
676
|
-
continue;
|
|
677
|
-
} else if (c === '?') {
|
|
678
|
-
this.state = this.S.PROC_INST_ENDING;
|
|
679
|
-
} else {
|
|
680
|
-
this.procInstBody += c;
|
|
681
|
-
}
|
|
682
|
-
continue;
|
|
683
|
-
case this.S.PROC_INST_ENDING:
|
|
684
|
-
if (c === '>') {
|
|
685
|
-
this.emitNode('onprocessinginstruction', {
|
|
686
|
-
name: this.procInstName,
|
|
687
|
-
body: this.procInstBody
|
|
688
|
-
});
|
|
689
|
-
this.procInstName = this.procInstBody = '';
|
|
690
|
-
this.state = this.S.TEXT;
|
|
691
|
-
} else {
|
|
692
|
-
this.procInstBody += "?".concat(c);
|
|
693
|
-
this.state = this.S.PROC_INST_BODY;
|
|
606
|
+
}
|
|
607
|
+
continue;
|
|
608
|
+
case this.S.DOCTYPE_QUOTED:
|
|
609
|
+
this.doctype += c;
|
|
610
|
+
if (c === this.q) {
|
|
611
|
+
this.q = '';
|
|
612
|
+
this.state = this.S.DOCTYPE;
|
|
613
|
+
}
|
|
614
|
+
continue;
|
|
615
|
+
case this.S.DOCTYPE_DTD:
|
|
616
|
+
this.doctype += c;
|
|
617
|
+
if (c === ']') {
|
|
618
|
+
this.state = this.S.DOCTYPE;
|
|
619
|
+
} else if (SAX.isQuote(c)) {
|
|
620
|
+
this.state = this.S.DOCTYPE_DTD_QUOTED;
|
|
621
|
+
this.q = c;
|
|
622
|
+
}
|
|
623
|
+
continue;
|
|
624
|
+
case this.S.DOCTYPE_DTD_QUOTED:
|
|
625
|
+
this.doctype += c;
|
|
626
|
+
if (c === this.q) {
|
|
627
|
+
this.state = this.S.DOCTYPE_DTD;
|
|
628
|
+
this.q = '';
|
|
629
|
+
}
|
|
630
|
+
continue;
|
|
631
|
+
case this.S.COMMENT:
|
|
632
|
+
if (c === '-') {
|
|
633
|
+
this.state = this.S.COMMENT_ENDING;
|
|
634
|
+
} else {
|
|
635
|
+
this.comment += c;
|
|
636
|
+
}
|
|
637
|
+
continue;
|
|
638
|
+
case this.S.COMMENT_ENDING:
|
|
639
|
+
if (c === '-') {
|
|
640
|
+
this.state = this.S.COMMENT_ENDED;
|
|
641
|
+
this.comment = this.textApplyOptions(this.comment);
|
|
642
|
+
if (this.comment) {
|
|
643
|
+
this.emitNode('oncomment', this.comment);
|
|
694
644
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
645
|
+
this.comment = '';
|
|
646
|
+
} else {
|
|
647
|
+
this.comment += "-".concat(c);
|
|
648
|
+
this.state = this.S.COMMENT;
|
|
649
|
+
}
|
|
650
|
+
continue;
|
|
651
|
+
case this.S.COMMENT_ENDED:
|
|
652
|
+
if (c !== '>') {
|
|
653
|
+
this.strictFail('Malformed comment');
|
|
654
|
+
this.comment += "--".concat(c);
|
|
655
|
+
this.state = this.S.COMMENT;
|
|
656
|
+
} else {
|
|
657
|
+
this.state = this.S.TEXT;
|
|
658
|
+
}
|
|
659
|
+
continue;
|
|
660
|
+
case this.S.CDATA:
|
|
661
|
+
if (c === ']') {
|
|
662
|
+
this.state = this.S.CDATA_ENDING;
|
|
663
|
+
} else {
|
|
664
|
+
this.cdata += c;
|
|
665
|
+
}
|
|
666
|
+
continue;
|
|
667
|
+
case this.S.CDATA_ENDING:
|
|
668
|
+
if (c === ']') {
|
|
669
|
+
this.state = this.S.CDATA_ENDING_2;
|
|
670
|
+
} else {
|
|
671
|
+
this.cdata += "]".concat(c);
|
|
672
|
+
this.state = this.S.CDATA;
|
|
673
|
+
}
|
|
674
|
+
continue;
|
|
675
|
+
case this.S.CDATA_ENDING_2:
|
|
676
|
+
if (c === '>') {
|
|
677
|
+
if (this.cdata) {
|
|
678
|
+
this.emitNode('oncdata', this.cdata);
|
|
711
679
|
}
|
|
680
|
+
this.emitNode('onclosecdata');
|
|
681
|
+
this.cdata = '';
|
|
682
|
+
this.state = this.S.TEXT;
|
|
683
|
+
} else if (c === ']') {
|
|
684
|
+
this.cdata += ']';
|
|
685
|
+
} else {
|
|
686
|
+
this.cdata += "]]".concat(c);
|
|
687
|
+
this.state = this.S.CDATA;
|
|
688
|
+
}
|
|
689
|
+
continue;
|
|
690
|
+
case this.S.PROC_INST:
|
|
691
|
+
if (c === '?') {
|
|
692
|
+
this.state = this.S.PROC_INST_ENDING;
|
|
693
|
+
} else if (SAX.isWhitespace(c)) {
|
|
694
|
+
this.state = this.S.PROC_INST_BODY;
|
|
695
|
+
} else {
|
|
696
|
+
this.procInstName += c;
|
|
697
|
+
}
|
|
698
|
+
continue;
|
|
699
|
+
case this.S.PROC_INST_BODY:
|
|
700
|
+
if (!this.procInstBody && SAX.isWhitespace(c)) {
|
|
712
701
|
continue;
|
|
713
|
-
|
|
702
|
+
} else if (c === '?') {
|
|
703
|
+
this.state = this.S.PROC_INST_ENDING;
|
|
704
|
+
} else {
|
|
705
|
+
this.procInstBody += c;
|
|
706
|
+
}
|
|
707
|
+
continue;
|
|
708
|
+
case this.S.PROC_INST_ENDING:
|
|
709
|
+
if (c === '>') {
|
|
710
|
+
this.emitNode('onprocessinginstruction', {
|
|
711
|
+
name: this.procInstName,
|
|
712
|
+
body: this.procInstBody
|
|
713
|
+
});
|
|
714
|
+
this.procInstName = this.procInstBody = '';
|
|
715
|
+
this.state = this.S.TEXT;
|
|
716
|
+
} else {
|
|
717
|
+
this.procInstBody += "?".concat(c);
|
|
718
|
+
this.state = this.S.PROC_INST_BODY;
|
|
719
|
+
}
|
|
720
|
+
continue;
|
|
721
|
+
case this.S.OPEN_TAG:
|
|
722
|
+
if (SAX.isMatch(nameBody, c)) {
|
|
723
|
+
this.tagName += c;
|
|
724
|
+
} else {
|
|
725
|
+
this.newTag();
|
|
714
726
|
if (c === '>') {
|
|
715
|
-
this.openTag(true);
|
|
716
|
-
this.closeTag();
|
|
717
|
-
} else {
|
|
718
|
-
this.strictFail('Forward-slash in opening tag not followed by >');
|
|
719
|
-
this.state = this.S.ATTRIB;
|
|
720
|
-
}
|
|
721
|
-
continue;
|
|
722
|
-
case this.S.ATTRIB:
|
|
723
|
-
if (SAX.isWhitespace(c)) {
|
|
724
|
-
continue;
|
|
725
|
-
} else if (c === '>') {
|
|
726
727
|
this.openTag();
|
|
727
728
|
} else if (c === '/') {
|
|
728
729
|
this.state = this.S.OPEN_TAG_SLASH;
|
|
729
|
-
} else if (SAX.isMatch(nameStart, c)) {
|
|
730
|
-
this.attribName = c;
|
|
731
|
-
this.attribValue = '';
|
|
732
|
-
this.state = this.S.ATTRIB_NAME;
|
|
733
730
|
} else {
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
continue;
|
|
737
|
-
case this.S.ATTRIB_NAME:
|
|
738
|
-
if (c === '=') {
|
|
739
|
-
this.state = this.S.ATTRIB_VALUE;
|
|
740
|
-
} else if (c === '>') {
|
|
741
|
-
this.strictFail('Attribute without value');
|
|
742
|
-
this.attribValue = this.attribName;
|
|
743
|
-
this.attrib();
|
|
744
|
-
this.openTag();
|
|
745
|
-
} else if (SAX.isWhitespace(c)) {
|
|
746
|
-
this.state = this.S.ATTRIB_NAME_SAW_WHITE;
|
|
747
|
-
} else if (SAX.isMatch(nameBody, c)) {
|
|
748
|
-
this.attribName += c;
|
|
749
|
-
} else {
|
|
750
|
-
this.strictFail('Invalid attribute name');
|
|
751
|
-
}
|
|
752
|
-
continue;
|
|
753
|
-
case this.S.ATTRIB_NAME_SAW_WHITE:
|
|
754
|
-
if (c === '=') {
|
|
755
|
-
this.state = this.S.ATTRIB_VALUE;
|
|
756
|
-
} else if (SAX.isWhitespace(c)) {
|
|
757
|
-
continue;
|
|
758
|
-
} else {
|
|
759
|
-
this.strictFail('Attribute without value');
|
|
760
|
-
this.tag.attributes[this.attribName] = '';
|
|
761
|
-
this.attribValue = '';
|
|
762
|
-
this.emitNode('onattribute', {
|
|
763
|
-
name: this.attribName,
|
|
764
|
-
value: ''
|
|
765
|
-
});
|
|
766
|
-
this.attribName = '';
|
|
767
|
-
if (c === '>') {
|
|
768
|
-
this.openTag();
|
|
769
|
-
} else if (SAX.isMatch(nameStart, c)) {
|
|
770
|
-
this.attribName = c;
|
|
771
|
-
this.state = this.S.ATTRIB_NAME;
|
|
772
|
-
} else {
|
|
773
|
-
this.strictFail('Invalid attribute name');
|
|
774
|
-
this.state = this.S.ATTRIB;
|
|
731
|
+
if (!SAX.isWhitespace(c)) {
|
|
732
|
+
this.strictFail('Invalid character in tag name');
|
|
775
733
|
}
|
|
734
|
+
this.state = this.S.ATTRIB;
|
|
776
735
|
}
|
|
736
|
+
}
|
|
737
|
+
continue;
|
|
738
|
+
case this.S.OPEN_TAG_SLASH:
|
|
739
|
+
if (c === '>') {
|
|
740
|
+
this.openTag(true);
|
|
741
|
+
this.closeTag();
|
|
742
|
+
} else {
|
|
743
|
+
this.strictFail('Forward-slash in opening tag not followed by >');
|
|
744
|
+
this.state = this.S.ATTRIB;
|
|
745
|
+
}
|
|
746
|
+
continue;
|
|
747
|
+
case this.S.ATTRIB:
|
|
748
|
+
if (SAX.isWhitespace(c)) {
|
|
777
749
|
continue;
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
}
|
|
797
|
-
continue;
|
|
798
|
-
}
|
|
750
|
+
} else if (c === '>') {
|
|
751
|
+
this.openTag();
|
|
752
|
+
} else if (c === '/') {
|
|
753
|
+
this.state = this.S.OPEN_TAG_SLASH;
|
|
754
|
+
} else if (SAX.isMatch(nameStart, c)) {
|
|
755
|
+
this.attribName = c;
|
|
756
|
+
this.attribValue = '';
|
|
757
|
+
this.state = this.S.ATTRIB_NAME;
|
|
758
|
+
} else {
|
|
759
|
+
this.strictFail('Invalid attribute name');
|
|
760
|
+
}
|
|
761
|
+
continue;
|
|
762
|
+
case this.S.ATTRIB_NAME:
|
|
763
|
+
if (c === '=') {
|
|
764
|
+
this.state = this.S.ATTRIB_VALUE;
|
|
765
|
+
} else if (c === '>') {
|
|
766
|
+
this.strictFail('Attribute without value');
|
|
767
|
+
this.attribValue = this.attribName;
|
|
799
768
|
this.attrib();
|
|
800
|
-
this.
|
|
801
|
-
|
|
769
|
+
this.openTag();
|
|
770
|
+
} else if (SAX.isWhitespace(c)) {
|
|
771
|
+
this.state = this.S.ATTRIB_NAME_SAW_WHITE;
|
|
772
|
+
} else if (SAX.isMatch(nameBody, c)) {
|
|
773
|
+
this.attribName += c;
|
|
774
|
+
} else {
|
|
775
|
+
this.strictFail('Invalid attribute name');
|
|
776
|
+
}
|
|
777
|
+
continue;
|
|
778
|
+
case this.S.ATTRIB_NAME_SAW_WHITE:
|
|
779
|
+
if (c === '=') {
|
|
780
|
+
this.state = this.S.ATTRIB_VALUE;
|
|
781
|
+
} else if (SAX.isWhitespace(c)) {
|
|
802
782
|
continue;
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
783
|
+
} else {
|
|
784
|
+
this.strictFail('Attribute without value');
|
|
785
|
+
this.tag.attributes[this.attribName] = '';
|
|
786
|
+
this.attribValue = '';
|
|
787
|
+
this.emitNode('onattribute', {
|
|
788
|
+
name: this.attribName,
|
|
789
|
+
value: ''
|
|
790
|
+
});
|
|
791
|
+
this.attribName = '';
|
|
792
|
+
if (c === '>') {
|
|
807
793
|
this.openTag();
|
|
808
|
-
} else if (c === '/') {
|
|
809
|
-
this.state = this.S.OPEN_TAG_SLASH;
|
|
810
794
|
} else if (SAX.isMatch(nameStart, c)) {
|
|
811
|
-
this.strictFail('No whitespace between attributes');
|
|
812
795
|
this.attribName = c;
|
|
813
|
-
this.attribValue = '';
|
|
814
796
|
this.state = this.S.ATTRIB_NAME;
|
|
815
797
|
} else {
|
|
816
798
|
this.strictFail('Invalid attribute name');
|
|
799
|
+
this.state = this.S.ATTRIB;
|
|
817
800
|
}
|
|
801
|
+
}
|
|
802
|
+
continue;
|
|
803
|
+
case this.S.ATTRIB_VALUE:
|
|
804
|
+
if (SAX.isWhitespace(c)) {
|
|
818
805
|
continue;
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
806
|
+
} else if (SAX.isQuote(c)) {
|
|
807
|
+
this.q = c;
|
|
808
|
+
this.state = this.S.ATTRIB_VALUE_QUOTED;
|
|
809
|
+
} else {
|
|
810
|
+
this.strictFail('Unquoted attribute value');
|
|
811
|
+
this.state = this.S.ATTRIB_VALUE_UNQUOTED;
|
|
812
|
+
this.attribValue = c;
|
|
813
|
+
}
|
|
814
|
+
continue;
|
|
815
|
+
case this.S.ATTRIB_VALUE_QUOTED:
|
|
816
|
+
if (c !== this.q) {
|
|
817
|
+
if (c === '&') {
|
|
818
|
+
this.state = this.S.ATTRIB_VALUE_ENTITY_Q;
|
|
831
819
|
} else {
|
|
832
|
-
this.
|
|
820
|
+
this.attribValue += c;
|
|
833
821
|
}
|
|
834
822
|
continue;
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
823
|
+
}
|
|
824
|
+
this.attrib();
|
|
825
|
+
this.q = '';
|
|
826
|
+
this.state = this.S.ATTRIB_VALUE_CLOSED;
|
|
827
|
+
continue;
|
|
828
|
+
case this.S.ATTRIB_VALUE_CLOSED:
|
|
829
|
+
if (SAX.isWhitespace(c)) {
|
|
830
|
+
this.state = this.S.ATTRIB;
|
|
831
|
+
} else if (c === '>') {
|
|
832
|
+
this.openTag();
|
|
833
|
+
} else if (c === '/') {
|
|
834
|
+
this.state = this.S.OPEN_TAG_SLASH;
|
|
835
|
+
} else if (SAX.isMatch(nameStart, c)) {
|
|
836
|
+
this.strictFail('No whitespace between attributes');
|
|
837
|
+
this.attribName = c;
|
|
838
|
+
this.attribValue = '';
|
|
839
|
+
this.state = this.S.ATTRIB_NAME;
|
|
840
|
+
} else {
|
|
841
|
+
this.strictFail('Invalid attribute name');
|
|
842
|
+
}
|
|
843
|
+
continue;
|
|
844
|
+
case this.S.ATTRIB_VALUE_UNQUOTED:
|
|
845
|
+
if (!SAX.isAttribEnd(c)) {
|
|
846
|
+
if (c === '&') {
|
|
847
|
+
this.state = this.S.ATTRIB_VALUE_ENTITY_U;
|
|
857
848
|
} else {
|
|
858
|
-
|
|
859
|
-
this.strictFail('Invalid tagname in closing tag');
|
|
860
|
-
}
|
|
861
|
-
this.state = this.S.CLOSE_TAG_SAW_WHITE;
|
|
849
|
+
this.attribValue += c;
|
|
862
850
|
}
|
|
863
851
|
continue;
|
|
864
|
-
|
|
852
|
+
}
|
|
853
|
+
this.attrib();
|
|
854
|
+
if (c === '>') {
|
|
855
|
+
this.openTag();
|
|
856
|
+
} else {
|
|
857
|
+
this.state = this.S.ATTRIB;
|
|
858
|
+
}
|
|
859
|
+
continue;
|
|
860
|
+
case this.S.CLOSE_TAG:
|
|
861
|
+
if (!this.tagName) {
|
|
865
862
|
if (SAX.isWhitespace(c)) {
|
|
866
863
|
continue;
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
|
|
864
|
+
} else if (SAX.notMatch(nameStart, c)) {
|
|
865
|
+
if (this.script) {
|
|
866
|
+
this.script += "</".concat(c);
|
|
867
|
+
this.state = this.S.SCRIPT;
|
|
868
|
+
} else {
|
|
869
|
+
this.strictFail('Invalid tagname in closing tag.');
|
|
870
|
+
}
|
|
870
871
|
} else {
|
|
871
|
-
this.
|
|
872
|
-
}
|
|
873
|
-
continue;
|
|
874
|
-
case this.S.TEXT_ENTITY:
|
|
875
|
-
case this.S.ATTRIB_VALUE_ENTITY_Q:
|
|
876
|
-
case this.S.ATTRIB_VALUE_ENTITY_U:
|
|
877
|
-
var returnState = void 0;
|
|
878
|
-
var buffer = void 0;
|
|
879
|
-
switch (this.state) {
|
|
880
|
-
case this.S.TEXT_ENTITY:
|
|
881
|
-
returnState = this.S.TEXT;
|
|
882
|
-
buffer = 'textNode';
|
|
883
|
-
break;
|
|
884
|
-
case this.S.ATTRIB_VALUE_ENTITY_Q:
|
|
885
|
-
returnState = this.S.ATTRIB_VALUE_QUOTED;
|
|
886
|
-
buffer = 'attribValue';
|
|
887
|
-
break;
|
|
888
|
-
case this.S.ATTRIB_VALUE_ENTITY_U:
|
|
889
|
-
returnState = this.S.ATTRIB_VALUE_UNQUOTED;
|
|
890
|
-
buffer = 'attribValue';
|
|
891
|
-
break;
|
|
892
|
-
default:
|
|
893
|
-
throw new Error("Unknown state: ".concat(this.state));
|
|
872
|
+
this.tagName = c;
|
|
894
873
|
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
this.
|
|
874
|
+
} else if (c === '>') {
|
|
875
|
+
this.closeTag();
|
|
876
|
+
} else if (SAX.isMatch(nameBody, c)) {
|
|
877
|
+
this.tagName += c;
|
|
878
|
+
} else if (this.script) {
|
|
879
|
+
this.script += "</".concat(this.tagName);
|
|
880
|
+
this.tagName = '';
|
|
881
|
+
this.state = this.S.SCRIPT;
|
|
882
|
+
} else {
|
|
883
|
+
if (!SAX.isWhitespace(c)) {
|
|
884
|
+
this.strictFail('Invalid tagname in closing tag');
|
|
906
885
|
}
|
|
886
|
+
this.state = this.S.CLOSE_TAG_SAW_WHITE;
|
|
887
|
+
}
|
|
888
|
+
continue;
|
|
889
|
+
case this.S.CLOSE_TAG_SAW_WHITE:
|
|
890
|
+
if (SAX.isWhitespace(c)) {
|
|
907
891
|
continue;
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
892
|
+
}
|
|
893
|
+
if (c === '>') {
|
|
894
|
+
this.closeTag();
|
|
895
|
+
} else {
|
|
896
|
+
this.strictFail('Invalid characters in closing tag');
|
|
897
|
+
}
|
|
898
|
+
continue;
|
|
899
|
+
case this.S.TEXT_ENTITY:
|
|
900
|
+
case this.S.ATTRIB_VALUE_ENTITY_Q:
|
|
901
|
+
case this.S.ATTRIB_VALUE_ENTITY_U:
|
|
902
|
+
let returnState;
|
|
903
|
+
let buffer;
|
|
904
|
+
switch (this.state) {
|
|
905
|
+
case this.S.TEXT_ENTITY:
|
|
906
|
+
returnState = this.S.TEXT;
|
|
907
|
+
buffer = 'textNode';
|
|
908
|
+
break;
|
|
909
|
+
case this.S.ATTRIB_VALUE_ENTITY_Q:
|
|
910
|
+
returnState = this.S.ATTRIB_VALUE_QUOTED;
|
|
911
|
+
buffer = 'attribValue';
|
|
912
|
+
break;
|
|
913
|
+
case this.S.ATTRIB_VALUE_ENTITY_U:
|
|
914
|
+
returnState = this.S.ATTRIB_VALUE_UNQUOTED;
|
|
915
|
+
buffer = 'attribValue';
|
|
916
|
+
break;
|
|
917
|
+
default:
|
|
918
|
+
throw new Error("Unknown state: ".concat(this.state));
|
|
919
|
+
}
|
|
920
|
+
if (c === ';') {
|
|
921
|
+
this[buffer] += this.parseEntity();
|
|
922
|
+
this.entity = '';
|
|
923
|
+
this.state = returnState;
|
|
924
|
+
} else if (SAX.isMatch(this.entity.length ? entityBody : entityStart, c)) {
|
|
925
|
+
this.entity += c;
|
|
926
|
+
} else {
|
|
927
|
+
this.strictFail('Invalid character in entity name');
|
|
928
|
+
this[buffer] += "&".concat(this.entity).concat(c);
|
|
929
|
+
this.entity = '';
|
|
930
|
+
this.state = returnState;
|
|
931
|
+
}
|
|
932
|
+
continue;
|
|
933
|
+
default:
|
|
934
|
+
throw new Error("Unknown state: ".concat(this.state));
|
|
914
935
|
}
|
|
915
|
-
return this;
|
|
916
936
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
value: function emit(event, data) {
|
|
920
|
-
if (this.events.hasOwnProperty(event)) {
|
|
921
|
-
var _eventName = event.replace(/^on/, '');
|
|
922
|
-
this.events[event](data, _eventName, this);
|
|
923
|
-
}
|
|
937
|
+
if (this.position >= this.bufferCheckPosition) {
|
|
938
|
+
this.checkBufferLength();
|
|
924
939
|
}
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
940
|
+
return this;
|
|
941
|
+
}
|
|
942
|
+
emit(event, data) {
|
|
943
|
+
if (this.events.hasOwnProperty(event)) {
|
|
944
|
+
const eventName = event.replace(/^on/, '');
|
|
945
|
+
this.events[event](data, eventName, this);
|
|
931
946
|
}
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
this
|
|
936
|
-
if (this.cdata !== '') {
|
|
937
|
-
this.emitNode('oncdata', this.cdata);
|
|
938
|
-
this.cdata = '';
|
|
939
|
-
}
|
|
940
|
-
if (this.script !== '') {
|
|
941
|
-
this.emitNode('onscript', this.script);
|
|
942
|
-
this.script = '';
|
|
943
|
-
}
|
|
947
|
+
}
|
|
948
|
+
clearBuffers() {
|
|
949
|
+
for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
|
|
950
|
+
this[this[i]] = '';
|
|
944
951
|
}
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
}
|
|
952
|
-
this.closeText();
|
|
953
|
-
this.c = '';
|
|
954
|
-
this.closed = true;
|
|
955
|
-
this.emit('onend');
|
|
956
|
-
return new SAXParser(this.opt);
|
|
952
|
+
}
|
|
953
|
+
flushBuffers() {
|
|
954
|
+
this.closeText();
|
|
955
|
+
if (this.cdata !== '') {
|
|
956
|
+
this.emitNode('oncdata', this.cdata);
|
|
957
|
+
this.cdata = '';
|
|
957
958
|
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
this.closeText();
|
|
962
|
-
if (this.trackPosition) {
|
|
963
|
-
er += "\nLine: ".concat(this.line, "\nColumn: ").concat(this.column, "\nChar: ").concat(this.c);
|
|
964
|
-
}
|
|
965
|
-
var error = new Error(er);
|
|
966
|
-
this.error = error;
|
|
967
|
-
this.emit('onerror', error);
|
|
968
|
-
return this;
|
|
959
|
+
if (this.script !== '') {
|
|
960
|
+
this.emitNode('onscript', this.script);
|
|
961
|
+
this.script = '';
|
|
969
962
|
}
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
}
|
|
976
|
-
if (this.attribList.indexOf(this.attribName) !== -1 || this.tag.attributes.hasOwnProperty(this.attribName)) {
|
|
977
|
-
this.attribName = this.attribValue = '';
|
|
978
|
-
return;
|
|
979
|
-
}
|
|
980
|
-
if (this.opt.xmlns) {
|
|
981
|
-
var qn = SAX.qname(this.attribName, true);
|
|
982
|
-
var prefix = qn.prefix;
|
|
983
|
-
var local = qn.local;
|
|
984
|
-
if (prefix === 'xmlns') {
|
|
985
|
-
if (local === 'xml' && this.attribValue !== this.XML_NAMESPACE) {
|
|
986
|
-
this.strictFail("xml: prefix must be bound to ".concat(this.XML_NAMESPACE, "\n") + "Actual: ".concat(this.attribValue));
|
|
987
|
-
} else if (local === 'xmlns' && this.attribValue !== this.XMLNS_NAMESPACE) {
|
|
988
|
-
this.strictFail("xmlns: prefix must be bound to ".concat(this.XMLNS_NAMESPACE, "\n") + "Actual: ".concat(this.attribValue));
|
|
989
|
-
} else {
|
|
990
|
-
var tag = this.tag;
|
|
991
|
-
var parent = this.tags[this.tags.length - 1] || this;
|
|
992
|
-
if (tag.ns === parent.ns) {
|
|
993
|
-
tag.ns = Object.create(parent.ns);
|
|
994
|
-
}
|
|
995
|
-
tag.ns[local] = this.attribValue;
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
this.attribList.push([this.attribName, this.attribValue]);
|
|
999
|
-
} else {
|
|
1000
|
-
this.tag.attributes[this.attribName] = this.attribValue;
|
|
1001
|
-
this.emitNode('onattribute', {
|
|
1002
|
-
name: this.attribName,
|
|
1003
|
-
value: this.attribValue
|
|
1004
|
-
});
|
|
1005
|
-
}
|
|
1006
|
-
this.attribName = this.attribValue = '';
|
|
963
|
+
}
|
|
964
|
+
end() {
|
|
965
|
+
if (this.sawRoot && !this.closedRoot) this.strictFail('Unclosed root tag');
|
|
966
|
+
if (this.state !== this.S.BEGIN && this.state !== this.S.BEGIN_WHITESPACE && this.state !== this.S.TEXT) {
|
|
967
|
+
this.errorFunction('Unexpected end');
|
|
1007
968
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
tag.ns = parent.ns;
|
|
1019
|
-
}
|
|
1020
|
-
this.attribList.length = 0;
|
|
1021
|
-
this.emitNode('onopentagstart', tag);
|
|
969
|
+
this.closeText();
|
|
970
|
+
this.c = '';
|
|
971
|
+
this.closed = true;
|
|
972
|
+
this.emit('onend');
|
|
973
|
+
return new SAXParser(this.opt);
|
|
974
|
+
}
|
|
975
|
+
errorFunction(er) {
|
|
976
|
+
this.closeText();
|
|
977
|
+
if (this.trackPosition) {
|
|
978
|
+
er += "\nLine: ".concat(this.line, "\nColumn: ").concat(this.column, "\nChar: ").concat(this.c);
|
|
1022
979
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
980
|
+
const error = new Error(er);
|
|
981
|
+
this.error = error;
|
|
982
|
+
this.emit('onerror', error);
|
|
983
|
+
return this;
|
|
984
|
+
}
|
|
985
|
+
attrib() {
|
|
986
|
+
if (!this.strict) {
|
|
987
|
+
this.attribName = this.attribName[this.looseCase]();
|
|
988
|
+
}
|
|
989
|
+
if (this.attribList.indexOf(this.attribName) !== -1 || this.tag.attributes.hasOwnProperty(this.attribName)) {
|
|
990
|
+
this.attribName = this.attribValue = '';
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
if (this.opt.xmlns) {
|
|
994
|
+
const qn = SAX.qname(this.attribName, true);
|
|
995
|
+
const prefix = qn.prefix;
|
|
996
|
+
const local = qn.local;
|
|
997
|
+
if (prefix === 'xmlns') {
|
|
998
|
+
if (local === 'xml' && this.attribValue !== this.XML_NAMESPACE) {
|
|
999
|
+
this.strictFail("xml: prefix must be bound to ".concat(this.XML_NAMESPACE, "\n") + "Actual: ".concat(this.attribValue));
|
|
1000
|
+
} else if (local === 'xmlns' && this.attribValue !== this.XMLNS_NAMESPACE) {
|
|
1001
|
+
this.strictFail("xmlns: prefix must be bound to ".concat(this.XMLNS_NAMESPACE, "\n") + "Actual: ".concat(this.attribValue));
|
|
1042
1002
|
} else {
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1003
|
+
const tag = this.tag;
|
|
1004
|
+
const parent = this.tags[this.tags.length - 1] || this;
|
|
1005
|
+
if (tag.ns === parent.ns) {
|
|
1006
|
+
tag.ns = Object.create(parent.ns);
|
|
1007
|
+
}
|
|
1008
|
+
tag.ns[local] = this.attribValue;
|
|
1046
1009
|
}
|
|
1047
1010
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1011
|
+
this.attribList.push([this.attribName, this.attribValue]);
|
|
1012
|
+
} else {
|
|
1013
|
+
this.tag.attributes[this.attribName] = this.attribValue;
|
|
1014
|
+
this.emitNode('onattribute', {
|
|
1015
|
+
name: this.attribName,
|
|
1016
|
+
value: this.attribValue
|
|
1017
|
+
});
|
|
1054
1018
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1019
|
+
this.attribName = this.attribValue = '';
|
|
1020
|
+
}
|
|
1021
|
+
newTag() {
|
|
1022
|
+
if (!this.strict) this.tagName = this.tagName[this.looseCase]();
|
|
1023
|
+
const parent = this.tags[this.tags.length - 1] || this;
|
|
1024
|
+
const tag = this.tag = {
|
|
1025
|
+
name: this.tagName,
|
|
1026
|
+
attributes: {}
|
|
1027
|
+
};
|
|
1028
|
+
if (this.opt.xmlns) {
|
|
1029
|
+
tag.ns = parent.ns;
|
|
1066
1030
|
}
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1031
|
+
this.attribList.length = 0;
|
|
1032
|
+
this.emitNode('onopentagstart', tag);
|
|
1033
|
+
}
|
|
1034
|
+
parseEntity() {
|
|
1035
|
+
let entity = this.entity;
|
|
1036
|
+
const entityLC = entity.toLowerCase();
|
|
1037
|
+
let num = NaN;
|
|
1038
|
+
let numStr = '';
|
|
1039
|
+
if (this.ENTITIES[entity]) {
|
|
1040
|
+
return this.ENTITIES[entity];
|
|
1041
|
+
}
|
|
1042
|
+
if (this.ENTITIES[entityLC]) {
|
|
1043
|
+
return this.ENTITIES[entityLC];
|
|
1044
|
+
}
|
|
1045
|
+
entity = entityLC;
|
|
1046
|
+
if (entity.charAt(0) === '#') {
|
|
1047
|
+
if (entity.charAt(1) === 'x') {
|
|
1048
|
+
entity = entity.slice(2);
|
|
1049
|
+
num = parseInt(entity, 16);
|
|
1050
|
+
numStr = num.toString(16);
|
|
1051
|
+
} else {
|
|
1052
|
+
entity = entity.slice(1);
|
|
1053
|
+
num = parseInt(entity, 10);
|
|
1054
|
+
numStr = num.toString(10);
|
|
1075
1055
|
}
|
|
1076
1056
|
}
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
if (this.opt.normalize) text = text.replace(/\s+/g, ' ');
|
|
1082
|
-
return text;
|
|
1057
|
+
entity = entity.replace(/^0+/, '');
|
|
1058
|
+
if (isNaN(num) || numStr.toLowerCase() !== entity) {
|
|
1059
|
+
this.strictFail('Invalid character entity');
|
|
1060
|
+
return "&".concat(this.entity, ";");
|
|
1083
1061
|
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
this.
|
|
1062
|
+
return String.fromCodePoint(num);
|
|
1063
|
+
}
|
|
1064
|
+
beginWhiteSpace(c) {
|
|
1065
|
+
if (c === '<') {
|
|
1066
|
+
this.state = this.S.OPEN_WAKA;
|
|
1067
|
+
this.startTagPosition = this.position;
|
|
1068
|
+
} else if (!SAX.isWhitespace(c)) {
|
|
1069
|
+
this.strictFail('Non-whitespace before first tag.');
|
|
1070
|
+
this.textNode = c;
|
|
1071
|
+
this.state = this.S.TEXT;
|
|
1072
|
+
} else {}
|
|
1073
|
+
}
|
|
1074
|
+
strictFail(message) {
|
|
1075
|
+
if (typeof this !== 'object' || !(this instanceof SAXParser)) {
|
|
1076
|
+
throw new Error('bad call to strictFail');
|
|
1089
1077
|
}
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
value: function closeText() {
|
|
1093
|
-
this.textNode = this.textApplyOptions(this.textNode);
|
|
1094
|
-
if (this.textNode !== undefined && this.textNode !== '' && this.textNode !== 'undefined') {
|
|
1095
|
-
this.emit('ontext', this.textNode);
|
|
1096
|
-
}
|
|
1097
|
-
this.textNode = '';
|
|
1078
|
+
if (this.strict) {
|
|
1079
|
+
this.errorFunction(message);
|
|
1098
1080
|
}
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1081
|
+
}
|
|
1082
|
+
textApplyOptions(text) {
|
|
1083
|
+
if (this.opt.trim) text = text.trim();
|
|
1084
|
+
if (this.opt.normalize) text = text.replace(/\s+/g, ' ');
|
|
1085
|
+
return text;
|
|
1086
|
+
}
|
|
1087
|
+
emitNode(nodeType, data) {
|
|
1088
|
+
if (this.textNode) this.closeText();
|
|
1089
|
+
this.emit(nodeType, data);
|
|
1090
|
+
}
|
|
1091
|
+
closeText() {
|
|
1092
|
+
this.textNode = this.textApplyOptions(this.textNode);
|
|
1093
|
+
if (this.textNode !== undefined && this.textNode !== '' && this.textNode !== 'undefined') {
|
|
1094
|
+
this.emit('ontext', this.textNode);
|
|
1095
|
+
}
|
|
1096
|
+
this.textNode = '';
|
|
1097
|
+
}
|
|
1098
|
+
checkBufferLength() {
|
|
1099
|
+
const maxAllowed = Math.max(this.opt.MAX_BUFFER_LENGTH, 10);
|
|
1100
|
+
let maxActual = 0;
|
|
1101
|
+
for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
|
|
1102
|
+
var _this$this$BUFFERS$i;
|
|
1103
|
+
const len = ((_this$this$BUFFERS$i = this[this.BUFFERS[i]]) === null || _this$this$BUFFERS$i === void 0 ? void 0 : _this$this$BUFFERS$i.length) || 0;
|
|
1104
|
+
if (len > maxAllowed) {
|
|
1105
|
+
switch (this.BUFFERS[i]) {
|
|
1106
|
+
case 'textNode':
|
|
1107
|
+
this.closeText();
|
|
1108
|
+
break;
|
|
1109
|
+
case 'cdata':
|
|
1110
|
+
this.emitNode('oncdata', this.cdata);
|
|
1111
|
+
this.cdata = '';
|
|
1112
|
+
break;
|
|
1113
|
+
case 'script':
|
|
1114
|
+
this.emitNode('onscript', this.script);
|
|
1115
|
+
this.script = '';
|
|
1116
|
+
break;
|
|
1117
|
+
default:
|
|
1118
|
+
this.errorFunction("Max buffer length exceeded: ".concat(this.BUFFERS[i]));
|
|
1123
1119
|
}
|
|
1124
|
-
maxActual = Math.max(maxActual, len);
|
|
1125
1120
|
}
|
|
1126
|
-
|
|
1127
|
-
this.bufferCheckPosition = m + this.position;
|
|
1121
|
+
maxActual = Math.max(maxActual, len);
|
|
1128
1122
|
}
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1123
|
+
const m = this.opt.MAX_BUFFER_LENGTH - maxActual;
|
|
1124
|
+
this.bufferCheckPosition = m + this.position;
|
|
1125
|
+
}
|
|
1126
|
+
openTag(selfClosing) {
|
|
1127
|
+
if (this.opt.xmlns) {
|
|
1128
|
+
const tag = this.tag;
|
|
1129
|
+
const qn = SAX.qname(this.tagName);
|
|
1130
|
+
tag.prefix = qn.prefix;
|
|
1131
|
+
tag.local = qn.local;
|
|
1132
|
+
tag.uri = tag.ns[qn.prefix] || '';
|
|
1133
|
+
if (tag.prefix && !tag.uri) {
|
|
1134
|
+
this.strictFail("Unbound namespace prefix: ".concat(JSON.stringify(this.tagName)));
|
|
1135
|
+
tag.uri = qn.prefix;
|
|
1136
|
+
}
|
|
1137
|
+
const parent = this.tags[this.tags.length - 1] || this;
|
|
1138
|
+
if (tag.ns && parent.ns !== tag.ns) {
|
|
1139
|
+
const that = this;
|
|
1140
|
+
Object.keys(tag.ns).forEach(p => {
|
|
1141
|
+
that.emitNode('onopennamespace', {
|
|
1142
|
+
prefix: p,
|
|
1143
|
+
uri: tag.ns[p]
|
|
1150
1144
|
});
|
|
1151
|
-
}
|
|
1152
|
-
for (var i = 0, l = this.attribList.length; i < l; i++) {
|
|
1153
|
-
var nv = this.attribList[i];
|
|
1154
|
-
var name = nv[0];
|
|
1155
|
-
var value = nv[1];
|
|
1156
|
-
var qualName = SAX.qname(name, true);
|
|
1157
|
-
var prefix = qualName.prefix;
|
|
1158
|
-
var local = qualName.local;
|
|
1159
|
-
var uri = prefix === '' ? '' : tag.ns[prefix] || '';
|
|
1160
|
-
var a = {
|
|
1161
|
-
name: name,
|
|
1162
|
-
value: value,
|
|
1163
|
-
prefix: prefix,
|
|
1164
|
-
local: local,
|
|
1165
|
-
uri: uri
|
|
1166
|
-
};
|
|
1167
|
-
if (prefix && prefix !== 'xmlns' && !uri) {
|
|
1168
|
-
this.strictFail("Unbound namespace prefix: ".concat(JSON.stringify(prefix)));
|
|
1169
|
-
a.uri = prefix;
|
|
1170
|
-
}
|
|
1171
|
-
this.tag.attributes[name] = a;
|
|
1172
|
-
this.emitNode('onattribute', a);
|
|
1173
|
-
}
|
|
1174
|
-
this.attribList.length = 0;
|
|
1145
|
+
});
|
|
1175
1146
|
}
|
|
1176
|
-
this.
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1147
|
+
for (let i = 0, l = this.attribList.length; i < l; i++) {
|
|
1148
|
+
const nv = this.attribList[i];
|
|
1149
|
+
const name = nv[0];
|
|
1150
|
+
const value = nv[1];
|
|
1151
|
+
const qualName = SAX.qname(name, true);
|
|
1152
|
+
const prefix = qualName.prefix;
|
|
1153
|
+
const local = qualName.local;
|
|
1154
|
+
const uri = prefix === '' ? '' : tag.ns[prefix] || '';
|
|
1155
|
+
const a = {
|
|
1156
|
+
name,
|
|
1157
|
+
value,
|
|
1158
|
+
prefix,
|
|
1159
|
+
local,
|
|
1160
|
+
uri
|
|
1161
|
+
};
|
|
1162
|
+
if (prefix && prefix !== 'xmlns' && !uri) {
|
|
1163
|
+
this.strictFail("Unbound namespace prefix: ".concat(JSON.stringify(prefix)));
|
|
1164
|
+
a.uri = prefix;
|
|
1185
1165
|
}
|
|
1186
|
-
this.tag =
|
|
1187
|
-
this.
|
|
1166
|
+
this.tag.attributes[name] = a;
|
|
1167
|
+
this.emitNode('onattribute', a);
|
|
1188
1168
|
}
|
|
1189
|
-
this.attribName = this.attribValue = '';
|
|
1190
1169
|
this.attribList.length = 0;
|
|
1191
1170
|
}
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
this.
|
|
1199
|
-
|
|
1200
|
-
return;
|
|
1201
|
-
}
|
|
1202
|
-
if (this.script) {
|
|
1203
|
-
if (this.tagName !== 'script') {
|
|
1204
|
-
this.script += "</".concat(this.tagName, ">");
|
|
1205
|
-
this.tagName = '';
|
|
1206
|
-
this.state = this.S.SCRIPT;
|
|
1207
|
-
return;
|
|
1208
|
-
}
|
|
1209
|
-
this.emitNode('onscript', this.script);
|
|
1210
|
-
this.script = '';
|
|
1211
|
-
}
|
|
1212
|
-
var t = this.tags.length;
|
|
1213
|
-
var tagName = this.tagName;
|
|
1214
|
-
if (!this.strict) {
|
|
1215
|
-
tagName = tagName[this.looseCase]();
|
|
1216
|
-
}
|
|
1217
|
-
while (t--) {
|
|
1218
|
-
var close = this.tags[t];
|
|
1219
|
-
if (close.name !== tagName) {
|
|
1220
|
-
this.strictFail('Unexpected close tag');
|
|
1221
|
-
} else {
|
|
1222
|
-
break;
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
if (t < 0) {
|
|
1226
|
-
this.strictFail("Unmatched closing tag: ".concat(this.tagName));
|
|
1227
|
-
this.textNode += "</".concat(this.tagName, ">");
|
|
1171
|
+
this.tag.isSelfClosing = Boolean(selfClosing);
|
|
1172
|
+
this.sawRoot = true;
|
|
1173
|
+
this.tags.push(this.tag);
|
|
1174
|
+
this.emitNode('onopentag', this.tag);
|
|
1175
|
+
if (!selfClosing) {
|
|
1176
|
+
if (!this.noscript && this.tagName.toLowerCase() === 'script') {
|
|
1177
|
+
this.state = this.S.SCRIPT;
|
|
1178
|
+
} else {
|
|
1228
1179
|
this.state = this.S.TEXT;
|
|
1229
|
-
return;
|
|
1230
|
-
}
|
|
1231
|
-
this.tagName = tagName;
|
|
1232
|
-
var s = this.tags.length;
|
|
1233
|
-
var _loop = function _loop() {
|
|
1234
|
-
var tag = _this.tag = _this.tags.pop();
|
|
1235
|
-
_this.tagName = _this.tag.name;
|
|
1236
|
-
_this.emitNode('onclosetag', _this.tagName);
|
|
1237
|
-
var x = {};
|
|
1238
|
-
for (var i in tag.ns) {
|
|
1239
|
-
if (tag.ns.hasOwnProperty(i)) {
|
|
1240
|
-
x[i] = tag.ns[i];
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
var parent = _this.tags[_this.tags.length - 1] || _this;
|
|
1244
|
-
if (_this.opt.xmlns && tag.ns !== parent.ns) {
|
|
1245
|
-
var that = _this;
|
|
1246
|
-
Object.keys(tag.ns).forEach(function (p) {
|
|
1247
|
-
var n = tag.ns[p];
|
|
1248
|
-
that.emitNode('onclosenamespace', {
|
|
1249
|
-
prefix: p,
|
|
1250
|
-
uri: n
|
|
1251
|
-
});
|
|
1252
|
-
});
|
|
1253
|
-
}
|
|
1254
|
-
};
|
|
1255
|
-
while (s-- > t) {
|
|
1256
|
-
_loop();
|
|
1257
1180
|
}
|
|
1258
|
-
|
|
1259
|
-
this.tagName =
|
|
1260
|
-
|
|
1181
|
+
this.tag = null;
|
|
1182
|
+
this.tagName = '';
|
|
1183
|
+
}
|
|
1184
|
+
this.attribName = this.attribValue = '';
|
|
1185
|
+
this.attribList.length = 0;
|
|
1186
|
+
}
|
|
1187
|
+
closeTag() {
|
|
1188
|
+
if (!this.tagName) {
|
|
1189
|
+
this.strictFail('Weird empty close tag.');
|
|
1190
|
+
this.textNode += '</>';
|
|
1261
1191
|
this.state = this.S.TEXT;
|
|
1192
|
+
return;
|
|
1262
1193
|
}
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1194
|
+
if (this.script) {
|
|
1195
|
+
if (this.tagName !== 'script') {
|
|
1196
|
+
this.script += "</".concat(this.tagName, ">");
|
|
1197
|
+
this.tagName = '';
|
|
1198
|
+
this.state = this.S.SCRIPT;
|
|
1199
|
+
return;
|
|
1269
1200
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
}, {
|
|
1273
|
-
key: "isWhitespace",
|
|
1274
|
-
value: function isWhitespace(c) {
|
|
1275
|
-
return c === ' ' || c === '\n' || c === '\r' || c === '\t';
|
|
1201
|
+
this.emitNode('onscript', this.script);
|
|
1202
|
+
this.script = '';
|
|
1276
1203
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1204
|
+
let t = this.tags.length;
|
|
1205
|
+
let tagName = this.tagName;
|
|
1206
|
+
if (!this.strict) {
|
|
1207
|
+
tagName = tagName[this.looseCase]();
|
|
1281
1208
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
key: "isMatch",
|
|
1289
|
-
value: function isMatch(regex, c) {
|
|
1290
|
-
return regex.test(c);
|
|
1291
|
-
}
|
|
1292
|
-
}, {
|
|
1293
|
-
key: "notMatch",
|
|
1294
|
-
value: function notMatch(regex, c) {
|
|
1295
|
-
return !SAX.isMatch(regex, c);
|
|
1296
|
-
}
|
|
1297
|
-
}, {
|
|
1298
|
-
key: "qname",
|
|
1299
|
-
value: function qname(name, attribute) {
|
|
1300
|
-
var i = name.indexOf(':');
|
|
1301
|
-
var qualName = i < 0 ? ['', name] : name.split(':');
|
|
1302
|
-
var prefix = qualName[0];
|
|
1303
|
-
var local = qualName[1];
|
|
1304
|
-
if (attribute && name === 'xmlns') {
|
|
1305
|
-
prefix = 'xmlns';
|
|
1306
|
-
local = '';
|
|
1209
|
+
while (t--) {
|
|
1210
|
+
const close = this.tags[t];
|
|
1211
|
+
if (close.name !== tagName) {
|
|
1212
|
+
this.strictFail('Unexpected close tag');
|
|
1213
|
+
} else {
|
|
1214
|
+
break;
|
|
1307
1215
|
}
|
|
1308
|
-
return {
|
|
1309
|
-
prefix: prefix,
|
|
1310
|
-
local: local
|
|
1311
|
-
};
|
|
1312
1216
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
var _super = _createSuper(SAXParser);
|
|
1319
|
-
function SAXParser(opt) {
|
|
1320
|
-
var _this2;
|
|
1321
|
-
(0, _classCallCheck2.default)(this, SAXParser);
|
|
1322
|
-
_this2 = _super.call(this);
|
|
1323
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "opt", DEFAULT_SAX_PARSER_OPTIONS);
|
|
1324
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "events", DEFAULT_SAX_EVENTS);
|
|
1325
|
-
_this2.clearBuffers();
|
|
1326
|
-
_this2.opt = opt = _objectSpread(_objectSpread({}, _this2.opt), opt);
|
|
1327
|
-
_this2.events = _objectSpread(_objectSpread({}, _this2.events), opt);
|
|
1328
|
-
_this2.q = _this2.c = '';
|
|
1329
|
-
_this2.opt.lowercase = _this2.opt.lowercase || _this2.opt.lowercasetags;
|
|
1330
|
-
_this2.bufferCheckPosition = _this2.opt.MAX_BUFFER_LENGTH;
|
|
1331
|
-
_this2.looseCase = _this2.opt.lowercase ? 'toLowerCase' : 'toUpperCase';
|
|
1332
|
-
_this2.tags = [];
|
|
1333
|
-
_this2.closed = _this2.closedRoot = _this2.sawRoot = false;
|
|
1334
|
-
_this2.tag = _this2.error = null;
|
|
1335
|
-
_this2.strict = Boolean(_this2.opt.strict);
|
|
1336
|
-
_this2.noscript = Boolean(_this2.opt.strict || _this2.opt.noscript);
|
|
1337
|
-
_this2.state = _this2.S.BEGIN;
|
|
1338
|
-
_this2.strictEntities = _this2.opt.strictEntities;
|
|
1339
|
-
_this2.ENTITIES = _this2.strictEntities ? Object.create(_this2.XML_ENTITIES) : Object.create(_this2.ENTITIES);
|
|
1340
|
-
_this2.attribList = [];
|
|
1341
|
-
if (_this2.opt.xmlns) {
|
|
1342
|
-
_this2.ns = Object.create(_this2.rootNS);
|
|
1217
|
+
if (t < 0) {
|
|
1218
|
+
this.strictFail("Unmatched closing tag: ".concat(this.tagName));
|
|
1219
|
+
this.textNode += "</".concat(this.tagName, ">");
|
|
1220
|
+
this.state = this.S.TEXT;
|
|
1221
|
+
return;
|
|
1343
1222
|
}
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1223
|
+
this.tagName = tagName;
|
|
1224
|
+
let s = this.tags.length;
|
|
1225
|
+
while (s-- > t) {
|
|
1226
|
+
const tag = this.tag = this.tags.pop();
|
|
1227
|
+
this.tagName = this.tag.name;
|
|
1228
|
+
this.emitNode('onclosetag', this.tagName);
|
|
1229
|
+
const x = {};
|
|
1230
|
+
for (const i in tag.ns) {
|
|
1231
|
+
if (tag.ns.hasOwnProperty(i)) {
|
|
1232
|
+
x[i] = tag.ns[i];
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
const parent = this.tags[this.tags.length - 1] || this;
|
|
1236
|
+
if (this.opt.xmlns && tag.ns !== parent.ns) {
|
|
1237
|
+
const that = this;
|
|
1238
|
+
Object.keys(tag.ns).forEach(p => {
|
|
1239
|
+
const n = tag.ns[p];
|
|
1240
|
+
that.emitNode('onclosenamespace', {
|
|
1241
|
+
prefix: p,
|
|
1242
|
+
uri: n
|
|
1243
|
+
});
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1347
1246
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1247
|
+
if (t === 0) this.closedRoot = true;
|
|
1248
|
+
this.tagName = this.attribValue = this.attribName = '';
|
|
1249
|
+
this.attribList.length = 0;
|
|
1250
|
+
this.state = this.S.TEXT;
|
|
1350
1251
|
}
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1252
|
+
}
|
|
1253
|
+
class SAXParser extends SAX {
|
|
1254
|
+
constructor(opt) {
|
|
1255
|
+
super();
|
|
1256
|
+
(0, _defineProperty2.default)(this, "opt", DEFAULT_SAX_PARSER_OPTIONS);
|
|
1257
|
+
(0, _defineProperty2.default)(this, "events", DEFAULT_SAX_EVENTS);
|
|
1258
|
+
this.clearBuffers();
|
|
1259
|
+
this.opt = opt = {
|
|
1260
|
+
...this.opt,
|
|
1261
|
+
...opt
|
|
1262
|
+
};
|
|
1263
|
+
this.events = {
|
|
1264
|
+
...this.events,
|
|
1265
|
+
...opt
|
|
1266
|
+
};
|
|
1267
|
+
this.q = this.c = '';
|
|
1268
|
+
this.opt.lowercase = this.opt.lowercase || this.opt.lowercasetags;
|
|
1269
|
+
this.bufferCheckPosition = this.opt.MAX_BUFFER_LENGTH;
|
|
1270
|
+
this.looseCase = this.opt.lowercase ? 'toLowerCase' : 'toUpperCase';
|
|
1271
|
+
this.tags = [];
|
|
1272
|
+
this.closed = this.closedRoot = this.sawRoot = false;
|
|
1273
|
+
this.tag = this.error = null;
|
|
1274
|
+
this.strict = Boolean(this.opt.strict);
|
|
1275
|
+
this.noscript = Boolean(this.opt.strict || this.opt.noscript);
|
|
1276
|
+
this.state = this.S.BEGIN;
|
|
1277
|
+
this.strictEntities = this.opt.strictEntities;
|
|
1278
|
+
this.ENTITIES = this.strictEntities ? Object.create(this.XML_ENTITIES) : Object.create(this.ENTITIES);
|
|
1279
|
+
this.attribList = [];
|
|
1280
|
+
if (this.opt.xmlns) {
|
|
1281
|
+
this.ns = Object.create(this.rootNS);
|
|
1356
1282
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
return this.write(null);
|
|
1283
|
+
this.trackPosition = this.opt.position !== false;
|
|
1284
|
+
if (this.trackPosition) {
|
|
1285
|
+
this.position = this.line = this.column = 0;
|
|
1361
1286
|
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
|
|
1287
|
+
this.emit('onready');
|
|
1288
|
+
}
|
|
1289
|
+
resume() {
|
|
1290
|
+
this.error = null;
|
|
1291
|
+
return this;
|
|
1292
|
+
}
|
|
1293
|
+
close() {
|
|
1294
|
+
return this.write(null);
|
|
1295
|
+
}
|
|
1296
|
+
flush() {
|
|
1297
|
+
this.flushBuffers();
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1370
1300
|
exports.SAXParser = SAXParser;
|
|
1371
1301
|
(0, _defineProperty2.default)(SAXParser, "ENTITIES", ENTITIES);
|
|
1372
1302
|
//# sourceMappingURL=sax.js.map
|