parse5 3.0.3 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -16
- package/lib/common/doctype.js +125 -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 -21
- 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 +32 -61
- package/LICENSE +0 -19
- 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
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var Mixin = require('../../utils/mixin'),
|
|
4
|
-
Tokenizer = require('../../tokenizer'),
|
|
5
|
-
PositionTrackingPreprocessorMixin = require('../position_tracking/preprocessor_mixin'),
|
|
6
|
-
inherits = require('util').inherits;
|
|
7
|
-
|
|
8
|
-
var LocationInfoTokenizerMixin = module.exports = function (tokenizer) {
|
|
9
|
-
Mixin.call(this, tokenizer);
|
|
10
|
-
|
|
11
|
-
this.tokenizer = tokenizer;
|
|
12
|
-
this.posTracker = new PositionTrackingPreprocessorMixin(tokenizer.preprocessor);
|
|
13
|
-
this.currentAttrLocation = null;
|
|
14
|
-
this.currentTokenLocation = null;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
inherits(LocationInfoTokenizerMixin, Mixin);
|
|
18
|
-
|
|
19
|
-
LocationInfoTokenizerMixin.prototype._getCurrentLocation = function () {
|
|
20
|
-
return {
|
|
21
|
-
line: this.posTracker.line,
|
|
22
|
-
col: this.posTracker.col,
|
|
23
|
-
startOffset: this.posTracker.offset,
|
|
24
|
-
endOffset: -1
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
LocationInfoTokenizerMixin.prototype._attachCurrentAttrLocationInfo = function () {
|
|
29
|
-
this.currentAttrLocation.endOffset = this.posTracker.offset;
|
|
30
|
-
|
|
31
|
-
var currentToken = this.tokenizer.currentToken,
|
|
32
|
-
currentAttr = this.tokenizer.currentAttr;
|
|
33
|
-
|
|
34
|
-
if (!currentToken.location.attrs)
|
|
35
|
-
currentToken.location.attrs = Object.create(null);
|
|
36
|
-
|
|
37
|
-
currentToken.location.attrs[currentAttr.name] = this.currentAttrLocation;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
LocationInfoTokenizerMixin.prototype._getOverriddenMethods = function (mxn, orig) {
|
|
41
|
-
var methods = {
|
|
42
|
-
_createStartTagToken: function () {
|
|
43
|
-
orig._createStartTagToken.call(this);
|
|
44
|
-
this.currentToken.location = mxn.currentTokenLocation;
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
_createEndTagToken: function () {
|
|
48
|
-
orig._createEndTagToken.call(this);
|
|
49
|
-
this.currentToken.location = mxn.currentTokenLocation;
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
_createCommentToken: function () {
|
|
53
|
-
orig._createCommentToken.call(this);
|
|
54
|
-
this.currentToken.location = mxn.currentTokenLocation;
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
_createDoctypeToken: function (initialName) {
|
|
58
|
-
orig._createDoctypeToken.call(this, initialName);
|
|
59
|
-
this.currentToken.location = mxn.currentTokenLocation;
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
_createCharacterToken: function (type, ch) {
|
|
63
|
-
orig._createCharacterToken.call(this, type, ch);
|
|
64
|
-
this.currentCharacterToken.location = mxn.currentTokenLocation;
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
_createAttr: function (attrNameFirstCh) {
|
|
68
|
-
orig._createAttr.call(this, attrNameFirstCh);
|
|
69
|
-
mxn.currentAttrLocation = mxn._getCurrentLocation();
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
_leaveAttrName: function (toState) {
|
|
73
|
-
orig._leaveAttrName.call(this, toState);
|
|
74
|
-
mxn._attachCurrentAttrLocationInfo();
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
_leaveAttrValue: function (toState) {
|
|
78
|
-
orig._leaveAttrValue.call(this, toState);
|
|
79
|
-
mxn._attachCurrentAttrLocationInfo();
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
_emitCurrentToken: function () {
|
|
83
|
-
//NOTE: if we have pending character token make it's end location equal to the
|
|
84
|
-
//current token's start location.
|
|
85
|
-
if (this.currentCharacterToken)
|
|
86
|
-
this.currentCharacterToken.location.endOffset = this.currentToken.location.startOffset;
|
|
87
|
-
|
|
88
|
-
this.currentToken.location.endOffset = mxn.posTracker.offset + 1;
|
|
89
|
-
orig._emitCurrentToken.call(this);
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
_emitCurrentCharacterToken: function () {
|
|
93
|
-
//NOTE: if we have character token and it's location wasn't set in the _emitCurrentToken(),
|
|
94
|
-
//then set it's location at the current preprocessor position.
|
|
95
|
-
//We don't need to increment preprocessor position, since character token
|
|
96
|
-
//emission is always forced by the start of the next character token here.
|
|
97
|
-
//So, we already have advanced position.
|
|
98
|
-
if (this.currentCharacterToken && this.currentCharacterToken.location.endOffset === -1)
|
|
99
|
-
this.currentCharacterToken.location.endOffset = mxn.posTracker.offset;
|
|
100
|
-
|
|
101
|
-
orig._emitCurrentCharacterToken.call(this);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
//NOTE: patch initial states for each mode to obtain token start position
|
|
106
|
-
Object.keys(Tokenizer.MODE).forEach(function (modeName) {
|
|
107
|
-
var state = Tokenizer.MODE[modeName];
|
|
108
|
-
|
|
109
|
-
methods[state] = function (cp) {
|
|
110
|
-
mxn.currentTokenLocation = mxn._getCurrentLocation();
|
|
111
|
-
orig[state].call(this, cp);
|
|
112
|
-
};
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
return methods;
|
|
116
|
-
};
|
|
117
|
-
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var Mixin = require('../../utils/mixin'),
|
|
4
|
-
inherits = require('util').inherits,
|
|
5
|
-
UNICODE = require('../../common/unicode');
|
|
6
|
-
|
|
7
|
-
//Aliases
|
|
8
|
-
var $ = UNICODE.CODE_POINTS;
|
|
9
|
-
|
|
10
|
-
var PositionTrackingPreprocessorMixin = module.exports = function (preprocessor) {
|
|
11
|
-
// NOTE: avoid installing tracker twice
|
|
12
|
-
if (!preprocessor.__locTracker) {
|
|
13
|
-
preprocessor.__locTracker = this;
|
|
14
|
-
|
|
15
|
-
Mixin.call(this, preprocessor);
|
|
16
|
-
|
|
17
|
-
this.preprocessor = preprocessor;
|
|
18
|
-
this.isEol = false;
|
|
19
|
-
this.lineStartPos = 0;
|
|
20
|
-
this.droppedBufferSize = 0;
|
|
21
|
-
|
|
22
|
-
this.col = -1;
|
|
23
|
-
this.line = 1;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return preprocessor.__locTracker;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
inherits(PositionTrackingPreprocessorMixin, Mixin);
|
|
30
|
-
|
|
31
|
-
Object.defineProperty(PositionTrackingPreprocessorMixin.prototype, 'offset', {
|
|
32
|
-
get: function () {
|
|
33
|
-
return this.droppedBufferSize + this.preprocessor.pos;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
PositionTrackingPreprocessorMixin.prototype._getOverriddenMethods = function (mxn, orig) {
|
|
38
|
-
return {
|
|
39
|
-
advance: function () {
|
|
40
|
-
var cp = orig.advance.call(this);
|
|
41
|
-
|
|
42
|
-
//NOTE: LF should be in the last column of the line
|
|
43
|
-
if (mxn.isEol) {
|
|
44
|
-
mxn.isEol = false;
|
|
45
|
-
mxn.line++;
|
|
46
|
-
mxn.lineStartPos = mxn.offset;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (cp === $.LINE_FEED)
|
|
50
|
-
mxn.isEol = true;
|
|
51
|
-
|
|
52
|
-
mxn.col = mxn.offset - mxn.lineStartPos + 1;
|
|
53
|
-
|
|
54
|
-
return cp;
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
retreat: function () {
|
|
58
|
-
orig.retreat.call(this);
|
|
59
|
-
mxn.isEol = false;
|
|
60
|
-
|
|
61
|
-
mxn.col = mxn.offset - mxn.lineStartPos + 1;
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
dropParsedChunk: function () {
|
|
65
|
-
var prevPos = this.pos;
|
|
66
|
-
|
|
67
|
-
orig.dropParsedChunk.call(this);
|
|
68
|
-
|
|
69
|
-
mxn.droppedBufferSize += prevPos - this.pos;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
};
|