@wabot-dev/framework 0.0.50 → 0.0.51
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/src/index.d.ts +2 -0
- package/dist/src/pre-made/module/html/HtmlModule.js +1 -1
- package/dist/src/repository/pg/PgCrudRepository.js +7 -0
- package/package.json +1 -1
- package/dist/src/_virtual/_commonjsHelpers.js +0 -5
- package/dist/src/_virtual/cjs.js +0 -7
- package/dist/src/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +0 -90
- package/dist/src/node_modules/deepmerge/dist/cjs.js +0 -142
- package/dist/src/node_modules/dom-serializer/lib/esm/foreignNames.js +0 -102
- package/dist/src/node_modules/dom-serializer/lib/esm/index.js +0 -186
- package/dist/src/node_modules/domelementtype/lib/esm/index.js +0 -53
- package/dist/src/node_modules/domhandler/lib/esm/index.js +0 -148
- package/dist/src/node_modules/domhandler/lib/esm/node.js +0 -334
- package/dist/src/node_modules/entities/lib/esm/decode.js +0 -458
- package/dist/src/node_modules/entities/lib/esm/decode_codepoint.js +0 -62
- package/dist/src/node_modules/entities/lib/esm/escape.js +0 -99
- package/dist/src/node_modules/entities/lib/esm/generated/decode-data-html.js +0 -8
- package/dist/src/node_modules/entities/lib/esm/generated/decode-data-xml.js +0 -8
- package/dist/src/node_modules/html-to-text/lib/html-to-text.js +0 -2147
- package/dist/src/node_modules/htmlparser2/lib/esm/Parser.js +0 -491
- package/dist/src/node_modules/htmlparser2/lib/esm/Tokenizer.js +0 -928
- package/dist/src/node_modules/htmlparser2/lib/esm/index.js +0 -18
- package/dist/src/node_modules/leac/lib/leac.js +0 -3
- package/dist/src/node_modules/parseley/lib/parseley.js +0 -270
- package/dist/src/node_modules/peberminta/lib/core.js +0 -171
- package/dist/src/node_modules/selderee/lib/selderee.js +0 -380
|
@@ -1,928 +0,0 @@
|
|
|
1
|
-
import { determineBranch, BinTrieFlags } from '../../../entities/lib/esm/decode.js';
|
|
2
|
-
import xmlDecodeTree from '../../../entities/lib/esm/generated/decode-data-xml.js';
|
|
3
|
-
import htmlDecodeTree from '../../../entities/lib/esm/generated/decode-data-html.js';
|
|
4
|
-
import { replaceCodePoint } from '../../../entities/lib/esm/decode_codepoint.js';
|
|
5
|
-
|
|
6
|
-
var CharCodes;
|
|
7
|
-
(function (CharCodes) {
|
|
8
|
-
CharCodes[CharCodes["Tab"] = 9] = "Tab";
|
|
9
|
-
CharCodes[CharCodes["NewLine"] = 10] = "NewLine";
|
|
10
|
-
CharCodes[CharCodes["FormFeed"] = 12] = "FormFeed";
|
|
11
|
-
CharCodes[CharCodes["CarriageReturn"] = 13] = "CarriageReturn";
|
|
12
|
-
CharCodes[CharCodes["Space"] = 32] = "Space";
|
|
13
|
-
CharCodes[CharCodes["ExclamationMark"] = 33] = "ExclamationMark";
|
|
14
|
-
CharCodes[CharCodes["Number"] = 35] = "Number";
|
|
15
|
-
CharCodes[CharCodes["Amp"] = 38] = "Amp";
|
|
16
|
-
CharCodes[CharCodes["SingleQuote"] = 39] = "SingleQuote";
|
|
17
|
-
CharCodes[CharCodes["DoubleQuote"] = 34] = "DoubleQuote";
|
|
18
|
-
CharCodes[CharCodes["Dash"] = 45] = "Dash";
|
|
19
|
-
CharCodes[CharCodes["Slash"] = 47] = "Slash";
|
|
20
|
-
CharCodes[CharCodes["Zero"] = 48] = "Zero";
|
|
21
|
-
CharCodes[CharCodes["Nine"] = 57] = "Nine";
|
|
22
|
-
CharCodes[CharCodes["Semi"] = 59] = "Semi";
|
|
23
|
-
CharCodes[CharCodes["Lt"] = 60] = "Lt";
|
|
24
|
-
CharCodes[CharCodes["Eq"] = 61] = "Eq";
|
|
25
|
-
CharCodes[CharCodes["Gt"] = 62] = "Gt";
|
|
26
|
-
CharCodes[CharCodes["Questionmark"] = 63] = "Questionmark";
|
|
27
|
-
CharCodes[CharCodes["UpperA"] = 65] = "UpperA";
|
|
28
|
-
CharCodes[CharCodes["LowerA"] = 97] = "LowerA";
|
|
29
|
-
CharCodes[CharCodes["UpperF"] = 70] = "UpperF";
|
|
30
|
-
CharCodes[CharCodes["LowerF"] = 102] = "LowerF";
|
|
31
|
-
CharCodes[CharCodes["UpperZ"] = 90] = "UpperZ";
|
|
32
|
-
CharCodes[CharCodes["LowerZ"] = 122] = "LowerZ";
|
|
33
|
-
CharCodes[CharCodes["LowerX"] = 120] = "LowerX";
|
|
34
|
-
CharCodes[CharCodes["OpeningSquareBracket"] = 91] = "OpeningSquareBracket";
|
|
35
|
-
})(CharCodes || (CharCodes = {}));
|
|
36
|
-
/** All the states the tokenizer can be in. */
|
|
37
|
-
var State;
|
|
38
|
-
(function (State) {
|
|
39
|
-
State[State["Text"] = 1] = "Text";
|
|
40
|
-
State[State["BeforeTagName"] = 2] = "BeforeTagName";
|
|
41
|
-
State[State["InTagName"] = 3] = "InTagName";
|
|
42
|
-
State[State["InSelfClosingTag"] = 4] = "InSelfClosingTag";
|
|
43
|
-
State[State["BeforeClosingTagName"] = 5] = "BeforeClosingTagName";
|
|
44
|
-
State[State["InClosingTagName"] = 6] = "InClosingTagName";
|
|
45
|
-
State[State["AfterClosingTagName"] = 7] = "AfterClosingTagName";
|
|
46
|
-
// Attributes
|
|
47
|
-
State[State["BeforeAttributeName"] = 8] = "BeforeAttributeName";
|
|
48
|
-
State[State["InAttributeName"] = 9] = "InAttributeName";
|
|
49
|
-
State[State["AfterAttributeName"] = 10] = "AfterAttributeName";
|
|
50
|
-
State[State["BeforeAttributeValue"] = 11] = "BeforeAttributeValue";
|
|
51
|
-
State[State["InAttributeValueDq"] = 12] = "InAttributeValueDq";
|
|
52
|
-
State[State["InAttributeValueSq"] = 13] = "InAttributeValueSq";
|
|
53
|
-
State[State["InAttributeValueNq"] = 14] = "InAttributeValueNq";
|
|
54
|
-
// Declarations
|
|
55
|
-
State[State["BeforeDeclaration"] = 15] = "BeforeDeclaration";
|
|
56
|
-
State[State["InDeclaration"] = 16] = "InDeclaration";
|
|
57
|
-
// Processing instructions
|
|
58
|
-
State[State["InProcessingInstruction"] = 17] = "InProcessingInstruction";
|
|
59
|
-
// Comments & CDATA
|
|
60
|
-
State[State["BeforeComment"] = 18] = "BeforeComment";
|
|
61
|
-
State[State["CDATASequence"] = 19] = "CDATASequence";
|
|
62
|
-
State[State["InSpecialComment"] = 20] = "InSpecialComment";
|
|
63
|
-
State[State["InCommentLike"] = 21] = "InCommentLike";
|
|
64
|
-
// Special tags
|
|
65
|
-
State[State["BeforeSpecialS"] = 22] = "BeforeSpecialS";
|
|
66
|
-
State[State["SpecialStartSequence"] = 23] = "SpecialStartSequence";
|
|
67
|
-
State[State["InSpecialTag"] = 24] = "InSpecialTag";
|
|
68
|
-
State[State["BeforeEntity"] = 25] = "BeforeEntity";
|
|
69
|
-
State[State["BeforeNumericEntity"] = 26] = "BeforeNumericEntity";
|
|
70
|
-
State[State["InNamedEntity"] = 27] = "InNamedEntity";
|
|
71
|
-
State[State["InNumericEntity"] = 28] = "InNumericEntity";
|
|
72
|
-
State[State["InHexEntity"] = 29] = "InHexEntity";
|
|
73
|
-
})(State || (State = {}));
|
|
74
|
-
function isWhitespace(c) {
|
|
75
|
-
return (c === CharCodes.Space ||
|
|
76
|
-
c === CharCodes.NewLine ||
|
|
77
|
-
c === CharCodes.Tab ||
|
|
78
|
-
c === CharCodes.FormFeed ||
|
|
79
|
-
c === CharCodes.CarriageReturn);
|
|
80
|
-
}
|
|
81
|
-
function isEndOfTagSection(c) {
|
|
82
|
-
return c === CharCodes.Slash || c === CharCodes.Gt || isWhitespace(c);
|
|
83
|
-
}
|
|
84
|
-
function isNumber(c) {
|
|
85
|
-
return c >= CharCodes.Zero && c <= CharCodes.Nine;
|
|
86
|
-
}
|
|
87
|
-
function isASCIIAlpha(c) {
|
|
88
|
-
return ((c >= CharCodes.LowerA && c <= CharCodes.LowerZ) ||
|
|
89
|
-
(c >= CharCodes.UpperA && c <= CharCodes.UpperZ));
|
|
90
|
-
}
|
|
91
|
-
function isHexDigit(c) {
|
|
92
|
-
return ((c >= CharCodes.UpperA && c <= CharCodes.UpperF) ||
|
|
93
|
-
(c >= CharCodes.LowerA && c <= CharCodes.LowerF));
|
|
94
|
-
}
|
|
95
|
-
var QuoteType;
|
|
96
|
-
(function (QuoteType) {
|
|
97
|
-
QuoteType[QuoteType["NoValue"] = 0] = "NoValue";
|
|
98
|
-
QuoteType[QuoteType["Unquoted"] = 1] = "Unquoted";
|
|
99
|
-
QuoteType[QuoteType["Single"] = 2] = "Single";
|
|
100
|
-
QuoteType[QuoteType["Double"] = 3] = "Double";
|
|
101
|
-
})(QuoteType || (QuoteType = {}));
|
|
102
|
-
/**
|
|
103
|
-
* Sequences used to match longer strings.
|
|
104
|
-
*
|
|
105
|
-
* We don't have `Script`, `Style`, or `Title` here. Instead, we re-use the *End
|
|
106
|
-
* sequences with an increased offset.
|
|
107
|
-
*/
|
|
108
|
-
const Sequences = {
|
|
109
|
-
Cdata: new Uint8Array([0x43, 0x44, 0x41, 0x54, 0x41, 0x5b]),
|
|
110
|
-
CdataEnd: new Uint8Array([0x5d, 0x5d, 0x3e]),
|
|
111
|
-
CommentEnd: new Uint8Array([0x2d, 0x2d, 0x3e]),
|
|
112
|
-
ScriptEnd: new Uint8Array([0x3c, 0x2f, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74]),
|
|
113
|
-
StyleEnd: new Uint8Array([0x3c, 0x2f, 0x73, 0x74, 0x79, 0x6c, 0x65]),
|
|
114
|
-
TitleEnd: new Uint8Array([0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65]), // `</title`
|
|
115
|
-
};
|
|
116
|
-
class Tokenizer {
|
|
117
|
-
constructor({ xmlMode = false, decodeEntities = true, }, cbs) {
|
|
118
|
-
this.cbs = cbs;
|
|
119
|
-
/** The current state the tokenizer is in. */
|
|
120
|
-
this.state = State.Text;
|
|
121
|
-
/** The read buffer. */
|
|
122
|
-
this.buffer = "";
|
|
123
|
-
/** The beginning of the section that is currently being read. */
|
|
124
|
-
this.sectionStart = 0;
|
|
125
|
-
/** The index within the buffer that we are currently looking at. */
|
|
126
|
-
this.index = 0;
|
|
127
|
-
/** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
|
|
128
|
-
this.baseState = State.Text;
|
|
129
|
-
/** For special parsing behavior inside of script and style tags. */
|
|
130
|
-
this.isSpecial = false;
|
|
131
|
-
/** Indicates whether the tokenizer has been paused. */
|
|
132
|
-
this.running = true;
|
|
133
|
-
/** The offset of the current buffer. */
|
|
134
|
-
this.offset = 0;
|
|
135
|
-
this.currentSequence = undefined;
|
|
136
|
-
this.sequenceIndex = 0;
|
|
137
|
-
this.trieIndex = 0;
|
|
138
|
-
this.trieCurrent = 0;
|
|
139
|
-
/** For named entities, the index of the value. For numeric entities, the code point. */
|
|
140
|
-
this.entityResult = 0;
|
|
141
|
-
this.entityExcess = 0;
|
|
142
|
-
this.xmlMode = xmlMode;
|
|
143
|
-
this.decodeEntities = decodeEntities;
|
|
144
|
-
this.entityTrie = xmlMode ? xmlDecodeTree : htmlDecodeTree;
|
|
145
|
-
}
|
|
146
|
-
reset() {
|
|
147
|
-
this.state = State.Text;
|
|
148
|
-
this.buffer = "";
|
|
149
|
-
this.sectionStart = 0;
|
|
150
|
-
this.index = 0;
|
|
151
|
-
this.baseState = State.Text;
|
|
152
|
-
this.currentSequence = undefined;
|
|
153
|
-
this.running = true;
|
|
154
|
-
this.offset = 0;
|
|
155
|
-
}
|
|
156
|
-
write(chunk) {
|
|
157
|
-
this.offset += this.buffer.length;
|
|
158
|
-
this.buffer = chunk;
|
|
159
|
-
this.parse();
|
|
160
|
-
}
|
|
161
|
-
end() {
|
|
162
|
-
if (this.running)
|
|
163
|
-
this.finish();
|
|
164
|
-
}
|
|
165
|
-
pause() {
|
|
166
|
-
this.running = false;
|
|
167
|
-
}
|
|
168
|
-
resume() {
|
|
169
|
-
this.running = true;
|
|
170
|
-
if (this.index < this.buffer.length + this.offset) {
|
|
171
|
-
this.parse();
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* The current index within all of the written data.
|
|
176
|
-
*/
|
|
177
|
-
getIndex() {
|
|
178
|
-
return this.index;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* The start of the current section.
|
|
182
|
-
*/
|
|
183
|
-
getSectionStart() {
|
|
184
|
-
return this.sectionStart;
|
|
185
|
-
}
|
|
186
|
-
stateText(c) {
|
|
187
|
-
if (c === CharCodes.Lt ||
|
|
188
|
-
(!this.decodeEntities && this.fastForwardTo(CharCodes.Lt))) {
|
|
189
|
-
if (this.index > this.sectionStart) {
|
|
190
|
-
this.cbs.ontext(this.sectionStart, this.index);
|
|
191
|
-
}
|
|
192
|
-
this.state = State.BeforeTagName;
|
|
193
|
-
this.sectionStart = this.index;
|
|
194
|
-
}
|
|
195
|
-
else if (this.decodeEntities && c === CharCodes.Amp) {
|
|
196
|
-
this.state = State.BeforeEntity;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
stateSpecialStartSequence(c) {
|
|
200
|
-
const isEnd = this.sequenceIndex === this.currentSequence.length;
|
|
201
|
-
const isMatch = isEnd
|
|
202
|
-
? // If we are at the end of the sequence, make sure the tag name has ended
|
|
203
|
-
isEndOfTagSection(c)
|
|
204
|
-
: // Otherwise, do a case-insensitive comparison
|
|
205
|
-
(c | 0x20) === this.currentSequence[this.sequenceIndex];
|
|
206
|
-
if (!isMatch) {
|
|
207
|
-
this.isSpecial = false;
|
|
208
|
-
}
|
|
209
|
-
else if (!isEnd) {
|
|
210
|
-
this.sequenceIndex++;
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
this.sequenceIndex = 0;
|
|
214
|
-
this.state = State.InTagName;
|
|
215
|
-
this.stateInTagName(c);
|
|
216
|
-
}
|
|
217
|
-
/** Look for an end tag. For <title> tags, also decode entities. */
|
|
218
|
-
stateInSpecialTag(c) {
|
|
219
|
-
if (this.sequenceIndex === this.currentSequence.length) {
|
|
220
|
-
if (c === CharCodes.Gt || isWhitespace(c)) {
|
|
221
|
-
const endOfText = this.index - this.currentSequence.length;
|
|
222
|
-
if (this.sectionStart < endOfText) {
|
|
223
|
-
// Spoof the index so that reported locations match up.
|
|
224
|
-
const actualIndex = this.index;
|
|
225
|
-
this.index = endOfText;
|
|
226
|
-
this.cbs.ontext(this.sectionStart, endOfText);
|
|
227
|
-
this.index = actualIndex;
|
|
228
|
-
}
|
|
229
|
-
this.isSpecial = false;
|
|
230
|
-
this.sectionStart = endOfText + 2; // Skip over the `</`
|
|
231
|
-
this.stateInClosingTagName(c);
|
|
232
|
-
return; // We are done; skip the rest of the function.
|
|
233
|
-
}
|
|
234
|
-
this.sequenceIndex = 0;
|
|
235
|
-
}
|
|
236
|
-
if ((c | 0x20) === this.currentSequence[this.sequenceIndex]) {
|
|
237
|
-
this.sequenceIndex += 1;
|
|
238
|
-
}
|
|
239
|
-
else if (this.sequenceIndex === 0) {
|
|
240
|
-
if (this.currentSequence === Sequences.TitleEnd) {
|
|
241
|
-
// We have to parse entities in <title> tags.
|
|
242
|
-
if (this.decodeEntities && c === CharCodes.Amp) {
|
|
243
|
-
this.state = State.BeforeEntity;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
else if (this.fastForwardTo(CharCodes.Lt)) {
|
|
247
|
-
// Outside of <title> tags, we can fast-forward.
|
|
248
|
-
this.sequenceIndex = 1;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
// If we see a `<`, set the sequence index to 1; useful for eg. `<</script>`.
|
|
253
|
-
this.sequenceIndex = Number(c === CharCodes.Lt);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
stateCDATASequence(c) {
|
|
257
|
-
if (c === Sequences.Cdata[this.sequenceIndex]) {
|
|
258
|
-
if (++this.sequenceIndex === Sequences.Cdata.length) {
|
|
259
|
-
this.state = State.InCommentLike;
|
|
260
|
-
this.currentSequence = Sequences.CdataEnd;
|
|
261
|
-
this.sequenceIndex = 0;
|
|
262
|
-
this.sectionStart = this.index + 1;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
this.sequenceIndex = 0;
|
|
267
|
-
this.state = State.InDeclaration;
|
|
268
|
-
this.stateInDeclaration(c); // Reconsume the character
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* When we wait for one specific character, we can speed things up
|
|
273
|
-
* by skipping through the buffer until we find it.
|
|
274
|
-
*
|
|
275
|
-
* @returns Whether the character was found.
|
|
276
|
-
*/
|
|
277
|
-
fastForwardTo(c) {
|
|
278
|
-
while (++this.index < this.buffer.length + this.offset) {
|
|
279
|
-
if (this.buffer.charCodeAt(this.index - this.offset) === c) {
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
/*
|
|
284
|
-
* We increment the index at the end of the `parse` loop,
|
|
285
|
-
* so set it to `buffer.length - 1` here.
|
|
286
|
-
*
|
|
287
|
-
* TODO: Refactor `parse` to increment index before calling states.
|
|
288
|
-
*/
|
|
289
|
-
this.index = this.buffer.length + this.offset - 1;
|
|
290
|
-
return false;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Comments and CDATA end with `-->` and `]]>`.
|
|
294
|
-
*
|
|
295
|
-
* Their common qualities are:
|
|
296
|
-
* - Their end sequences have a distinct character they start with.
|
|
297
|
-
* - That character is then repeated, so we have to check multiple repeats.
|
|
298
|
-
* - All characters but the start character of the sequence can be skipped.
|
|
299
|
-
*/
|
|
300
|
-
stateInCommentLike(c) {
|
|
301
|
-
if (c === this.currentSequence[this.sequenceIndex]) {
|
|
302
|
-
if (++this.sequenceIndex === this.currentSequence.length) {
|
|
303
|
-
if (this.currentSequence === Sequences.CdataEnd) {
|
|
304
|
-
this.cbs.oncdata(this.sectionStart, this.index, 2);
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
this.cbs.oncomment(this.sectionStart, this.index, 2);
|
|
308
|
-
}
|
|
309
|
-
this.sequenceIndex = 0;
|
|
310
|
-
this.sectionStart = this.index + 1;
|
|
311
|
-
this.state = State.Text;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
else if (this.sequenceIndex === 0) {
|
|
315
|
-
// Fast-forward to the first character of the sequence
|
|
316
|
-
if (this.fastForwardTo(this.currentSequence[0])) {
|
|
317
|
-
this.sequenceIndex = 1;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
else if (c !== this.currentSequence[this.sequenceIndex - 1]) {
|
|
321
|
-
// Allow long sequences, eg. --->, ]]]>
|
|
322
|
-
this.sequenceIndex = 0;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* HTML only allows ASCII alpha characters (a-z and A-Z) at the beginning of a tag name.
|
|
327
|
-
*
|
|
328
|
-
* XML allows a lot more characters here (@see https://www.w3.org/TR/REC-xml/#NT-NameStartChar).
|
|
329
|
-
* We allow anything that wouldn't end the tag.
|
|
330
|
-
*/
|
|
331
|
-
isTagStartChar(c) {
|
|
332
|
-
return this.xmlMode ? !isEndOfTagSection(c) : isASCIIAlpha(c);
|
|
333
|
-
}
|
|
334
|
-
startSpecial(sequence, offset) {
|
|
335
|
-
this.isSpecial = true;
|
|
336
|
-
this.currentSequence = sequence;
|
|
337
|
-
this.sequenceIndex = offset;
|
|
338
|
-
this.state = State.SpecialStartSequence;
|
|
339
|
-
}
|
|
340
|
-
stateBeforeTagName(c) {
|
|
341
|
-
if (c === CharCodes.ExclamationMark) {
|
|
342
|
-
this.state = State.BeforeDeclaration;
|
|
343
|
-
this.sectionStart = this.index + 1;
|
|
344
|
-
}
|
|
345
|
-
else if (c === CharCodes.Questionmark) {
|
|
346
|
-
this.state = State.InProcessingInstruction;
|
|
347
|
-
this.sectionStart = this.index + 1;
|
|
348
|
-
}
|
|
349
|
-
else if (this.isTagStartChar(c)) {
|
|
350
|
-
const lower = c | 0x20;
|
|
351
|
-
this.sectionStart = this.index;
|
|
352
|
-
if (!this.xmlMode && lower === Sequences.TitleEnd[2]) {
|
|
353
|
-
this.startSpecial(Sequences.TitleEnd, 3);
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
this.state =
|
|
357
|
-
!this.xmlMode && lower === Sequences.ScriptEnd[2]
|
|
358
|
-
? State.BeforeSpecialS
|
|
359
|
-
: State.InTagName;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
else if (c === CharCodes.Slash) {
|
|
363
|
-
this.state = State.BeforeClosingTagName;
|
|
364
|
-
}
|
|
365
|
-
else {
|
|
366
|
-
this.state = State.Text;
|
|
367
|
-
this.stateText(c);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
stateInTagName(c) {
|
|
371
|
-
if (isEndOfTagSection(c)) {
|
|
372
|
-
this.cbs.onopentagname(this.sectionStart, this.index);
|
|
373
|
-
this.sectionStart = -1;
|
|
374
|
-
this.state = State.BeforeAttributeName;
|
|
375
|
-
this.stateBeforeAttributeName(c);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
stateBeforeClosingTagName(c) {
|
|
379
|
-
if (isWhitespace(c)) ;
|
|
380
|
-
else if (c === CharCodes.Gt) {
|
|
381
|
-
this.state = State.Text;
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
this.state = this.isTagStartChar(c)
|
|
385
|
-
? State.InClosingTagName
|
|
386
|
-
: State.InSpecialComment;
|
|
387
|
-
this.sectionStart = this.index;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
stateInClosingTagName(c) {
|
|
391
|
-
if (c === CharCodes.Gt || isWhitespace(c)) {
|
|
392
|
-
this.cbs.onclosetag(this.sectionStart, this.index);
|
|
393
|
-
this.sectionStart = -1;
|
|
394
|
-
this.state = State.AfterClosingTagName;
|
|
395
|
-
this.stateAfterClosingTagName(c);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
stateAfterClosingTagName(c) {
|
|
399
|
-
// Skip everything until ">"
|
|
400
|
-
if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) {
|
|
401
|
-
this.state = State.Text;
|
|
402
|
-
this.baseState = State.Text;
|
|
403
|
-
this.sectionStart = this.index + 1;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
stateBeforeAttributeName(c) {
|
|
407
|
-
if (c === CharCodes.Gt) {
|
|
408
|
-
this.cbs.onopentagend(this.index);
|
|
409
|
-
if (this.isSpecial) {
|
|
410
|
-
this.state = State.InSpecialTag;
|
|
411
|
-
this.sequenceIndex = 0;
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
414
|
-
this.state = State.Text;
|
|
415
|
-
}
|
|
416
|
-
this.baseState = this.state;
|
|
417
|
-
this.sectionStart = this.index + 1;
|
|
418
|
-
}
|
|
419
|
-
else if (c === CharCodes.Slash) {
|
|
420
|
-
this.state = State.InSelfClosingTag;
|
|
421
|
-
}
|
|
422
|
-
else if (!isWhitespace(c)) {
|
|
423
|
-
this.state = State.InAttributeName;
|
|
424
|
-
this.sectionStart = this.index;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
stateInSelfClosingTag(c) {
|
|
428
|
-
if (c === CharCodes.Gt) {
|
|
429
|
-
this.cbs.onselfclosingtag(this.index);
|
|
430
|
-
this.state = State.Text;
|
|
431
|
-
this.baseState = State.Text;
|
|
432
|
-
this.sectionStart = this.index + 1;
|
|
433
|
-
this.isSpecial = false; // Reset special state, in case of self-closing special tags
|
|
434
|
-
}
|
|
435
|
-
else if (!isWhitespace(c)) {
|
|
436
|
-
this.state = State.BeforeAttributeName;
|
|
437
|
-
this.stateBeforeAttributeName(c);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
stateInAttributeName(c) {
|
|
441
|
-
if (c === CharCodes.Eq || isEndOfTagSection(c)) {
|
|
442
|
-
this.cbs.onattribname(this.sectionStart, this.index);
|
|
443
|
-
this.sectionStart = -1;
|
|
444
|
-
this.state = State.AfterAttributeName;
|
|
445
|
-
this.stateAfterAttributeName(c);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
stateAfterAttributeName(c) {
|
|
449
|
-
if (c === CharCodes.Eq) {
|
|
450
|
-
this.state = State.BeforeAttributeValue;
|
|
451
|
-
}
|
|
452
|
-
else if (c === CharCodes.Slash || c === CharCodes.Gt) {
|
|
453
|
-
this.cbs.onattribend(QuoteType.NoValue, this.index);
|
|
454
|
-
this.state = State.BeforeAttributeName;
|
|
455
|
-
this.stateBeforeAttributeName(c);
|
|
456
|
-
}
|
|
457
|
-
else if (!isWhitespace(c)) {
|
|
458
|
-
this.cbs.onattribend(QuoteType.NoValue, this.index);
|
|
459
|
-
this.state = State.InAttributeName;
|
|
460
|
-
this.sectionStart = this.index;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
stateBeforeAttributeValue(c) {
|
|
464
|
-
if (c === CharCodes.DoubleQuote) {
|
|
465
|
-
this.state = State.InAttributeValueDq;
|
|
466
|
-
this.sectionStart = this.index + 1;
|
|
467
|
-
}
|
|
468
|
-
else if (c === CharCodes.SingleQuote) {
|
|
469
|
-
this.state = State.InAttributeValueSq;
|
|
470
|
-
this.sectionStart = this.index + 1;
|
|
471
|
-
}
|
|
472
|
-
else if (!isWhitespace(c)) {
|
|
473
|
-
this.sectionStart = this.index;
|
|
474
|
-
this.state = State.InAttributeValueNq;
|
|
475
|
-
this.stateInAttributeValueNoQuotes(c); // Reconsume token
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
handleInAttributeValue(c, quote) {
|
|
479
|
-
if (c === quote ||
|
|
480
|
-
(!this.decodeEntities && this.fastForwardTo(quote))) {
|
|
481
|
-
this.cbs.onattribdata(this.sectionStart, this.index);
|
|
482
|
-
this.sectionStart = -1;
|
|
483
|
-
this.cbs.onattribend(quote === CharCodes.DoubleQuote
|
|
484
|
-
? QuoteType.Double
|
|
485
|
-
: QuoteType.Single, this.index);
|
|
486
|
-
this.state = State.BeforeAttributeName;
|
|
487
|
-
}
|
|
488
|
-
else if (this.decodeEntities && c === CharCodes.Amp) {
|
|
489
|
-
this.baseState = this.state;
|
|
490
|
-
this.state = State.BeforeEntity;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
stateInAttributeValueDoubleQuotes(c) {
|
|
494
|
-
this.handleInAttributeValue(c, CharCodes.DoubleQuote);
|
|
495
|
-
}
|
|
496
|
-
stateInAttributeValueSingleQuotes(c) {
|
|
497
|
-
this.handleInAttributeValue(c, CharCodes.SingleQuote);
|
|
498
|
-
}
|
|
499
|
-
stateInAttributeValueNoQuotes(c) {
|
|
500
|
-
if (isWhitespace(c) || c === CharCodes.Gt) {
|
|
501
|
-
this.cbs.onattribdata(this.sectionStart, this.index);
|
|
502
|
-
this.sectionStart = -1;
|
|
503
|
-
this.cbs.onattribend(QuoteType.Unquoted, this.index);
|
|
504
|
-
this.state = State.BeforeAttributeName;
|
|
505
|
-
this.stateBeforeAttributeName(c);
|
|
506
|
-
}
|
|
507
|
-
else if (this.decodeEntities && c === CharCodes.Amp) {
|
|
508
|
-
this.baseState = this.state;
|
|
509
|
-
this.state = State.BeforeEntity;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
stateBeforeDeclaration(c) {
|
|
513
|
-
if (c === CharCodes.OpeningSquareBracket) {
|
|
514
|
-
this.state = State.CDATASequence;
|
|
515
|
-
this.sequenceIndex = 0;
|
|
516
|
-
}
|
|
517
|
-
else {
|
|
518
|
-
this.state =
|
|
519
|
-
c === CharCodes.Dash
|
|
520
|
-
? State.BeforeComment
|
|
521
|
-
: State.InDeclaration;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
stateInDeclaration(c) {
|
|
525
|
-
if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) {
|
|
526
|
-
this.cbs.ondeclaration(this.sectionStart, this.index);
|
|
527
|
-
this.state = State.Text;
|
|
528
|
-
this.sectionStart = this.index + 1;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
stateInProcessingInstruction(c) {
|
|
532
|
-
if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) {
|
|
533
|
-
this.cbs.onprocessinginstruction(this.sectionStart, this.index);
|
|
534
|
-
this.state = State.Text;
|
|
535
|
-
this.sectionStart = this.index + 1;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
stateBeforeComment(c) {
|
|
539
|
-
if (c === CharCodes.Dash) {
|
|
540
|
-
this.state = State.InCommentLike;
|
|
541
|
-
this.currentSequence = Sequences.CommentEnd;
|
|
542
|
-
// Allow short comments (eg. <!-->)
|
|
543
|
-
this.sequenceIndex = 2;
|
|
544
|
-
this.sectionStart = this.index + 1;
|
|
545
|
-
}
|
|
546
|
-
else {
|
|
547
|
-
this.state = State.InDeclaration;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
stateInSpecialComment(c) {
|
|
551
|
-
if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) {
|
|
552
|
-
this.cbs.oncomment(this.sectionStart, this.index, 0);
|
|
553
|
-
this.state = State.Text;
|
|
554
|
-
this.sectionStart = this.index + 1;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
stateBeforeSpecialS(c) {
|
|
558
|
-
const lower = c | 0x20;
|
|
559
|
-
if (lower === Sequences.ScriptEnd[3]) {
|
|
560
|
-
this.startSpecial(Sequences.ScriptEnd, 4);
|
|
561
|
-
}
|
|
562
|
-
else if (lower === Sequences.StyleEnd[3]) {
|
|
563
|
-
this.startSpecial(Sequences.StyleEnd, 4);
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
this.state = State.InTagName;
|
|
567
|
-
this.stateInTagName(c); // Consume the token again
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
stateBeforeEntity(c) {
|
|
571
|
-
// Start excess with 1 to include the '&'
|
|
572
|
-
this.entityExcess = 1;
|
|
573
|
-
this.entityResult = 0;
|
|
574
|
-
if (c === CharCodes.Number) {
|
|
575
|
-
this.state = State.BeforeNumericEntity;
|
|
576
|
-
}
|
|
577
|
-
else if (c === CharCodes.Amp) ;
|
|
578
|
-
else {
|
|
579
|
-
this.trieIndex = 0;
|
|
580
|
-
this.trieCurrent = this.entityTrie[0];
|
|
581
|
-
this.state = State.InNamedEntity;
|
|
582
|
-
this.stateInNamedEntity(c);
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
stateInNamedEntity(c) {
|
|
586
|
-
this.entityExcess += 1;
|
|
587
|
-
this.trieIndex = determineBranch(this.entityTrie, this.trieCurrent, this.trieIndex + 1, c);
|
|
588
|
-
if (this.trieIndex < 0) {
|
|
589
|
-
this.emitNamedEntity();
|
|
590
|
-
this.index--;
|
|
591
|
-
return;
|
|
592
|
-
}
|
|
593
|
-
this.trieCurrent = this.entityTrie[this.trieIndex];
|
|
594
|
-
const masked = this.trieCurrent & BinTrieFlags.VALUE_LENGTH;
|
|
595
|
-
// If the branch is a value, store it and continue
|
|
596
|
-
if (masked) {
|
|
597
|
-
// The mask is the number of bytes of the value, including the current byte.
|
|
598
|
-
const valueLength = (masked >> 14) - 1;
|
|
599
|
-
// If we have a legacy entity while parsing strictly, just skip the number of bytes
|
|
600
|
-
if (!this.allowLegacyEntity() && c !== CharCodes.Semi) {
|
|
601
|
-
this.trieIndex += valueLength;
|
|
602
|
-
}
|
|
603
|
-
else {
|
|
604
|
-
// Add 1 as we have already incremented the excess
|
|
605
|
-
const entityStart = this.index - this.entityExcess + 1;
|
|
606
|
-
if (entityStart > this.sectionStart) {
|
|
607
|
-
this.emitPartial(this.sectionStart, entityStart);
|
|
608
|
-
}
|
|
609
|
-
// If this is a surrogate pair, consume the next two bytes
|
|
610
|
-
this.entityResult = this.trieIndex;
|
|
611
|
-
this.trieIndex += valueLength;
|
|
612
|
-
this.entityExcess = 0;
|
|
613
|
-
this.sectionStart = this.index + 1;
|
|
614
|
-
if (valueLength === 0) {
|
|
615
|
-
this.emitNamedEntity();
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
emitNamedEntity() {
|
|
621
|
-
this.state = this.baseState;
|
|
622
|
-
if (this.entityResult === 0) {
|
|
623
|
-
return;
|
|
624
|
-
}
|
|
625
|
-
const valueLength = (this.entityTrie[this.entityResult] & BinTrieFlags.VALUE_LENGTH) >>
|
|
626
|
-
14;
|
|
627
|
-
switch (valueLength) {
|
|
628
|
-
case 1: {
|
|
629
|
-
this.emitCodePoint(this.entityTrie[this.entityResult] &
|
|
630
|
-
~BinTrieFlags.VALUE_LENGTH);
|
|
631
|
-
break;
|
|
632
|
-
}
|
|
633
|
-
case 2: {
|
|
634
|
-
this.emitCodePoint(this.entityTrie[this.entityResult + 1]);
|
|
635
|
-
break;
|
|
636
|
-
}
|
|
637
|
-
case 3: {
|
|
638
|
-
this.emitCodePoint(this.entityTrie[this.entityResult + 1]);
|
|
639
|
-
this.emitCodePoint(this.entityTrie[this.entityResult + 2]);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
stateBeforeNumericEntity(c) {
|
|
644
|
-
if ((c | 0x20) === CharCodes.LowerX) {
|
|
645
|
-
this.entityExcess++;
|
|
646
|
-
this.state = State.InHexEntity;
|
|
647
|
-
}
|
|
648
|
-
else {
|
|
649
|
-
this.state = State.InNumericEntity;
|
|
650
|
-
this.stateInNumericEntity(c);
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
emitNumericEntity(strict) {
|
|
654
|
-
const entityStart = this.index - this.entityExcess - 1;
|
|
655
|
-
const numberStart = entityStart + 2 + Number(this.state === State.InHexEntity);
|
|
656
|
-
if (numberStart !== this.index) {
|
|
657
|
-
// Emit leading data if any
|
|
658
|
-
if (entityStart > this.sectionStart) {
|
|
659
|
-
this.emitPartial(this.sectionStart, entityStart);
|
|
660
|
-
}
|
|
661
|
-
this.sectionStart = this.index + Number(strict);
|
|
662
|
-
this.emitCodePoint(replaceCodePoint(this.entityResult));
|
|
663
|
-
}
|
|
664
|
-
this.state = this.baseState;
|
|
665
|
-
}
|
|
666
|
-
stateInNumericEntity(c) {
|
|
667
|
-
if (c === CharCodes.Semi) {
|
|
668
|
-
this.emitNumericEntity(true);
|
|
669
|
-
}
|
|
670
|
-
else if (isNumber(c)) {
|
|
671
|
-
this.entityResult = this.entityResult * 10 + (c - CharCodes.Zero);
|
|
672
|
-
this.entityExcess++;
|
|
673
|
-
}
|
|
674
|
-
else {
|
|
675
|
-
if (this.allowLegacyEntity()) {
|
|
676
|
-
this.emitNumericEntity(false);
|
|
677
|
-
}
|
|
678
|
-
else {
|
|
679
|
-
this.state = this.baseState;
|
|
680
|
-
}
|
|
681
|
-
this.index--;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
stateInHexEntity(c) {
|
|
685
|
-
if (c === CharCodes.Semi) {
|
|
686
|
-
this.emitNumericEntity(true);
|
|
687
|
-
}
|
|
688
|
-
else if (isNumber(c)) {
|
|
689
|
-
this.entityResult = this.entityResult * 16 + (c - CharCodes.Zero);
|
|
690
|
-
this.entityExcess++;
|
|
691
|
-
}
|
|
692
|
-
else if (isHexDigit(c)) {
|
|
693
|
-
this.entityResult =
|
|
694
|
-
this.entityResult * 16 + ((c | 0x20) - CharCodes.LowerA + 10);
|
|
695
|
-
this.entityExcess++;
|
|
696
|
-
}
|
|
697
|
-
else {
|
|
698
|
-
if (this.allowLegacyEntity()) {
|
|
699
|
-
this.emitNumericEntity(false);
|
|
700
|
-
}
|
|
701
|
-
else {
|
|
702
|
-
this.state = this.baseState;
|
|
703
|
-
}
|
|
704
|
-
this.index--;
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
allowLegacyEntity() {
|
|
708
|
-
return (!this.xmlMode &&
|
|
709
|
-
(this.baseState === State.Text ||
|
|
710
|
-
this.baseState === State.InSpecialTag));
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* Remove data that has already been consumed from the buffer.
|
|
714
|
-
*/
|
|
715
|
-
cleanup() {
|
|
716
|
-
// If we are inside of text or attributes, emit what we already have.
|
|
717
|
-
if (this.running && this.sectionStart !== this.index) {
|
|
718
|
-
if (this.state === State.Text ||
|
|
719
|
-
(this.state === State.InSpecialTag && this.sequenceIndex === 0)) {
|
|
720
|
-
this.cbs.ontext(this.sectionStart, this.index);
|
|
721
|
-
this.sectionStart = this.index;
|
|
722
|
-
}
|
|
723
|
-
else if (this.state === State.InAttributeValueDq ||
|
|
724
|
-
this.state === State.InAttributeValueSq ||
|
|
725
|
-
this.state === State.InAttributeValueNq) {
|
|
726
|
-
this.cbs.onattribdata(this.sectionStart, this.index);
|
|
727
|
-
this.sectionStart = this.index;
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
shouldContinue() {
|
|
732
|
-
return this.index < this.buffer.length + this.offset && this.running;
|
|
733
|
-
}
|
|
734
|
-
/**
|
|
735
|
-
* Iterates through the buffer, calling the function corresponding to the current state.
|
|
736
|
-
*
|
|
737
|
-
* States that are more likely to be hit are higher up, as a performance improvement.
|
|
738
|
-
*/
|
|
739
|
-
parse() {
|
|
740
|
-
while (this.shouldContinue()) {
|
|
741
|
-
const c = this.buffer.charCodeAt(this.index - this.offset);
|
|
742
|
-
switch (this.state) {
|
|
743
|
-
case State.Text: {
|
|
744
|
-
this.stateText(c);
|
|
745
|
-
break;
|
|
746
|
-
}
|
|
747
|
-
case State.SpecialStartSequence: {
|
|
748
|
-
this.stateSpecialStartSequence(c);
|
|
749
|
-
break;
|
|
750
|
-
}
|
|
751
|
-
case State.InSpecialTag: {
|
|
752
|
-
this.stateInSpecialTag(c);
|
|
753
|
-
break;
|
|
754
|
-
}
|
|
755
|
-
case State.CDATASequence: {
|
|
756
|
-
this.stateCDATASequence(c);
|
|
757
|
-
break;
|
|
758
|
-
}
|
|
759
|
-
case State.InAttributeValueDq: {
|
|
760
|
-
this.stateInAttributeValueDoubleQuotes(c);
|
|
761
|
-
break;
|
|
762
|
-
}
|
|
763
|
-
case State.InAttributeName: {
|
|
764
|
-
this.stateInAttributeName(c);
|
|
765
|
-
break;
|
|
766
|
-
}
|
|
767
|
-
case State.InCommentLike: {
|
|
768
|
-
this.stateInCommentLike(c);
|
|
769
|
-
break;
|
|
770
|
-
}
|
|
771
|
-
case State.InSpecialComment: {
|
|
772
|
-
this.stateInSpecialComment(c);
|
|
773
|
-
break;
|
|
774
|
-
}
|
|
775
|
-
case State.BeforeAttributeName: {
|
|
776
|
-
this.stateBeforeAttributeName(c);
|
|
777
|
-
break;
|
|
778
|
-
}
|
|
779
|
-
case State.InTagName: {
|
|
780
|
-
this.stateInTagName(c);
|
|
781
|
-
break;
|
|
782
|
-
}
|
|
783
|
-
case State.InClosingTagName: {
|
|
784
|
-
this.stateInClosingTagName(c);
|
|
785
|
-
break;
|
|
786
|
-
}
|
|
787
|
-
case State.BeforeTagName: {
|
|
788
|
-
this.stateBeforeTagName(c);
|
|
789
|
-
break;
|
|
790
|
-
}
|
|
791
|
-
case State.AfterAttributeName: {
|
|
792
|
-
this.stateAfterAttributeName(c);
|
|
793
|
-
break;
|
|
794
|
-
}
|
|
795
|
-
case State.InAttributeValueSq: {
|
|
796
|
-
this.stateInAttributeValueSingleQuotes(c);
|
|
797
|
-
break;
|
|
798
|
-
}
|
|
799
|
-
case State.BeforeAttributeValue: {
|
|
800
|
-
this.stateBeforeAttributeValue(c);
|
|
801
|
-
break;
|
|
802
|
-
}
|
|
803
|
-
case State.BeforeClosingTagName: {
|
|
804
|
-
this.stateBeforeClosingTagName(c);
|
|
805
|
-
break;
|
|
806
|
-
}
|
|
807
|
-
case State.AfterClosingTagName: {
|
|
808
|
-
this.stateAfterClosingTagName(c);
|
|
809
|
-
break;
|
|
810
|
-
}
|
|
811
|
-
case State.BeforeSpecialS: {
|
|
812
|
-
this.stateBeforeSpecialS(c);
|
|
813
|
-
break;
|
|
814
|
-
}
|
|
815
|
-
case State.InAttributeValueNq: {
|
|
816
|
-
this.stateInAttributeValueNoQuotes(c);
|
|
817
|
-
break;
|
|
818
|
-
}
|
|
819
|
-
case State.InSelfClosingTag: {
|
|
820
|
-
this.stateInSelfClosingTag(c);
|
|
821
|
-
break;
|
|
822
|
-
}
|
|
823
|
-
case State.InDeclaration: {
|
|
824
|
-
this.stateInDeclaration(c);
|
|
825
|
-
break;
|
|
826
|
-
}
|
|
827
|
-
case State.BeforeDeclaration: {
|
|
828
|
-
this.stateBeforeDeclaration(c);
|
|
829
|
-
break;
|
|
830
|
-
}
|
|
831
|
-
case State.BeforeComment: {
|
|
832
|
-
this.stateBeforeComment(c);
|
|
833
|
-
break;
|
|
834
|
-
}
|
|
835
|
-
case State.InProcessingInstruction: {
|
|
836
|
-
this.stateInProcessingInstruction(c);
|
|
837
|
-
break;
|
|
838
|
-
}
|
|
839
|
-
case State.InNamedEntity: {
|
|
840
|
-
this.stateInNamedEntity(c);
|
|
841
|
-
break;
|
|
842
|
-
}
|
|
843
|
-
case State.BeforeEntity: {
|
|
844
|
-
this.stateBeforeEntity(c);
|
|
845
|
-
break;
|
|
846
|
-
}
|
|
847
|
-
case State.InHexEntity: {
|
|
848
|
-
this.stateInHexEntity(c);
|
|
849
|
-
break;
|
|
850
|
-
}
|
|
851
|
-
case State.InNumericEntity: {
|
|
852
|
-
this.stateInNumericEntity(c);
|
|
853
|
-
break;
|
|
854
|
-
}
|
|
855
|
-
default: {
|
|
856
|
-
// `this._state === State.BeforeNumericEntity`
|
|
857
|
-
this.stateBeforeNumericEntity(c);
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
this.index++;
|
|
861
|
-
}
|
|
862
|
-
this.cleanup();
|
|
863
|
-
}
|
|
864
|
-
finish() {
|
|
865
|
-
if (this.state === State.InNamedEntity) {
|
|
866
|
-
this.emitNamedEntity();
|
|
867
|
-
}
|
|
868
|
-
// If there is remaining data, emit it in a reasonable way
|
|
869
|
-
if (this.sectionStart < this.index) {
|
|
870
|
-
this.handleTrailingData();
|
|
871
|
-
}
|
|
872
|
-
this.cbs.onend();
|
|
873
|
-
}
|
|
874
|
-
/** Handle any trailing data. */
|
|
875
|
-
handleTrailingData() {
|
|
876
|
-
const endIndex = this.buffer.length + this.offset;
|
|
877
|
-
if (this.state === State.InCommentLike) {
|
|
878
|
-
if (this.currentSequence === Sequences.CdataEnd) {
|
|
879
|
-
this.cbs.oncdata(this.sectionStart, endIndex, 0);
|
|
880
|
-
}
|
|
881
|
-
else {
|
|
882
|
-
this.cbs.oncomment(this.sectionStart, endIndex, 0);
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
else if (this.state === State.InNumericEntity &&
|
|
886
|
-
this.allowLegacyEntity()) {
|
|
887
|
-
this.emitNumericEntity(false);
|
|
888
|
-
// All trailing data will have been consumed
|
|
889
|
-
}
|
|
890
|
-
else if (this.state === State.InHexEntity &&
|
|
891
|
-
this.allowLegacyEntity()) {
|
|
892
|
-
this.emitNumericEntity(false);
|
|
893
|
-
// All trailing data will have been consumed
|
|
894
|
-
}
|
|
895
|
-
else if (this.state === State.InTagName ||
|
|
896
|
-
this.state === State.BeforeAttributeName ||
|
|
897
|
-
this.state === State.BeforeAttributeValue ||
|
|
898
|
-
this.state === State.AfterAttributeName ||
|
|
899
|
-
this.state === State.InAttributeName ||
|
|
900
|
-
this.state === State.InAttributeValueSq ||
|
|
901
|
-
this.state === State.InAttributeValueDq ||
|
|
902
|
-
this.state === State.InAttributeValueNq ||
|
|
903
|
-
this.state === State.InClosingTagName) ;
|
|
904
|
-
else {
|
|
905
|
-
this.cbs.ontext(this.sectionStart, endIndex);
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
emitPartial(start, endIndex) {
|
|
909
|
-
if (this.baseState !== State.Text &&
|
|
910
|
-
this.baseState !== State.InSpecialTag) {
|
|
911
|
-
this.cbs.onattribdata(start, endIndex);
|
|
912
|
-
}
|
|
913
|
-
else {
|
|
914
|
-
this.cbs.ontext(start, endIndex);
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
emitCodePoint(cp) {
|
|
918
|
-
if (this.baseState !== State.Text &&
|
|
919
|
-
this.baseState !== State.InSpecialTag) {
|
|
920
|
-
this.cbs.onattribentity(cp);
|
|
921
|
-
}
|
|
922
|
-
else {
|
|
923
|
-
this.cbs.ontextentity(cp);
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
export { QuoteType, Tokenizer as default };
|