parse5 7.2.1 → 7.3.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/dist/cjs/parser/formatting-element-list.js +4 -4
- package/dist/cjs/parser/index.d.ts +1 -1
- package/dist/cjs/parser/index.js +13 -8
- package/dist/cjs/parser/open-element-stack.d.ts +2 -2
- package/dist/cjs/parser/open-element-stack.js +11 -7
- package/dist/cjs/serializer/index.js +3 -3
- package/dist/cjs/tokenizer/index.d.ts +1 -1
- package/dist/cjs/tokenizer/index.js +3 -3
- package/dist/parser/formatting-element-list.js +4 -4
- package/dist/parser/index.d.ts +1 -1
- package/dist/parser/index.js +13 -8
- package/dist/parser/open-element-stack.d.ts +2 -2
- package/dist/parser/open-element-stack.js +11 -7
- package/dist/serializer/index.js +1 -1
- package/dist/tokenizer/index.d.ts +1 -1
- package/dist/tokenizer/index.js +1 -1
- package/package.json +3 -3
|
@@ -84,7 +84,7 @@ class FormattingElementList {
|
|
|
84
84
|
}
|
|
85
85
|
removeEntry(entry) {
|
|
86
86
|
const entryIndex = this.entries.indexOf(entry);
|
|
87
|
-
if (entryIndex
|
|
87
|
+
if (entryIndex !== -1) {
|
|
88
88
|
this.entries.splice(entryIndex, 1);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -95,11 +95,11 @@ class FormattingElementList {
|
|
|
95
95
|
*/
|
|
96
96
|
clearToLastMarker() {
|
|
97
97
|
const markerIdx = this.entries.indexOf(MARKER);
|
|
98
|
-
if (markerIdx
|
|
99
|
-
this.entries.
|
|
98
|
+
if (markerIdx === -1) {
|
|
99
|
+
this.entries.length = 0;
|
|
100
100
|
}
|
|
101
101
|
else {
|
|
102
|
-
this.entries.
|
|
102
|
+
this.entries.splice(0, markerIdx + 1);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
//Search
|
|
@@ -122,7 +122,7 @@ export declare class Parser<T extends TreeAdapterTypeMap> implements TokenHandle
|
|
|
122
122
|
onItemPush(node: T['parentNode'], tid: number, isTop: boolean): void;
|
|
123
123
|
/** @internal */
|
|
124
124
|
onItemPop(node: T['parentNode'], isTop: boolean): void;
|
|
125
|
-
protected _setContextModes(current: T['parentNode'], tid: number): void;
|
|
125
|
+
protected _setContextModes(current: T['parentNode'] | undefined, tid: number | undefined): void;
|
|
126
126
|
/** @protected */
|
|
127
127
|
_switchToTextParsing(currentToken: TagToken, nextTokenizerState: (typeof TokenizerMode)[keyof typeof TokenizerMode]): void;
|
|
128
128
|
switchToPlaintextParsing(): void;
|
package/dist/cjs/parser/index.js
CHANGED
|
@@ -188,9 +188,10 @@ class Parser {
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
_setContextModes(current, tid) {
|
|
191
|
-
const isHTML = current === this.document || this.treeAdapter.getNamespaceURI(current) === html_js_1.NS.HTML;
|
|
191
|
+
const isHTML = current === this.document || (current && this.treeAdapter.getNamespaceURI(current) === html_js_1.NS.HTML);
|
|
192
192
|
this.currentNotInHTML = !isHTML;
|
|
193
|
-
this.tokenizer.inForeignNode =
|
|
193
|
+
this.tokenizer.inForeignNode =
|
|
194
|
+
!isHTML && current !== undefined && tid !== undefined && !this._isIntegrationPoint(tid, current);
|
|
194
195
|
}
|
|
195
196
|
/** @protected */
|
|
196
197
|
_switchToTextParsing(currentToken, nextTokenizerState) {
|
|
@@ -279,7 +280,7 @@ class Parser {
|
|
|
279
280
|
}
|
|
280
281
|
else {
|
|
281
282
|
const parent = this.openElements.currentTmplContentOrNode;
|
|
282
|
-
this.treeAdapter.appendChild(parent, element);
|
|
283
|
+
this.treeAdapter.appendChild(parent !== null && parent !== void 0 ? parent : this.document, element);
|
|
283
284
|
}
|
|
284
285
|
}
|
|
285
286
|
/**
|
|
@@ -416,6 +417,7 @@ class Parser {
|
|
|
416
417
|
// If it _is_ an integration point, then we might have to check that it is not an HTML
|
|
417
418
|
// integration point.
|
|
418
419
|
((token.tagID === html_js_1.TAG_ID.MGLYPH || token.tagID === html_js_1.TAG_ID.MALIGNMARK) &&
|
|
420
|
+
currentTagId !== undefined &&
|
|
419
421
|
!this._isIntegrationPoint(currentTagId, current, html_js_1.NS.HTML)));
|
|
420
422
|
}
|
|
421
423
|
/** @protected */
|
|
@@ -468,7 +470,7 @@ class Parser {
|
|
|
468
470
|
const listLength = this.activeFormattingElements.entries.length;
|
|
469
471
|
if (listLength) {
|
|
470
472
|
const endIndex = this.activeFormattingElements.entries.findIndex((entry) => entry.type === formatting_element_list_js_1.EntryType.Marker || this.openElements.contains(entry.element));
|
|
471
|
-
const unopenIdx = endIndex
|
|
473
|
+
const unopenIdx = endIndex === -1 ? listLength - 1 : endIndex - 1;
|
|
472
474
|
for (let i = unopenIdx; i >= 0; i--) {
|
|
473
475
|
const entry = this.activeFormattingElements.entries[i];
|
|
474
476
|
this._insertElement(entry.token, this.treeAdapter.getNamespaceURI(entry.element));
|
|
@@ -579,7 +581,9 @@ class Parser {
|
|
|
579
581
|
}
|
|
580
582
|
/** @protected */
|
|
581
583
|
_shouldFosterParentOnInsertion() {
|
|
582
|
-
return this.fosterParentingEnabled &&
|
|
584
|
+
return (this.fosterParentingEnabled &&
|
|
585
|
+
this.openElements.currentTagId !== undefined &&
|
|
586
|
+
this._isElementCausesFosterParenting(this.openElements.currentTagId));
|
|
583
587
|
}
|
|
584
588
|
/** @protected */
|
|
585
589
|
_findFosterParentingLocation() {
|
|
@@ -1199,7 +1203,7 @@ function aaObtainFurthestBlock(p, formattingElementEntry) {
|
|
|
1199
1203
|
}
|
|
1200
1204
|
}
|
|
1201
1205
|
if (!furthestBlock) {
|
|
1202
|
-
p.openElements.shortenToLength(idx
|
|
1206
|
+
p.openElements.shortenToLength(Math.max(idx, 0));
|
|
1203
1207
|
p.activeFormattingElements.removeEntry(formattingElementEntry);
|
|
1204
1208
|
}
|
|
1205
1209
|
return furthestBlock;
|
|
@@ -1685,7 +1689,7 @@ function numberedHeaderStartTagInBody(p, token) {
|
|
|
1685
1689
|
if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
|
|
1686
1690
|
p._closePElement();
|
|
1687
1691
|
}
|
|
1688
|
-
if (html_js_1.NUMBERED_HEADERS.has(p.openElements.currentTagId)) {
|
|
1692
|
+
if (p.openElements.currentTagId !== undefined && html_js_1.NUMBERED_HEADERS.has(p.openElements.currentTagId)) {
|
|
1689
1693
|
p.openElements.pop();
|
|
1690
1694
|
}
|
|
1691
1695
|
p._insertElement(token, html_js_1.NS.HTML);
|
|
@@ -2358,7 +2362,7 @@ function eofInText(p, token) {
|
|
|
2358
2362
|
// The "in table" insertion mode
|
|
2359
2363
|
//------------------------------------------------------------------
|
|
2360
2364
|
function characterInTable(p, token) {
|
|
2361
|
-
if (TABLE_STRUCTURE_TAGS.has(p.openElements.currentTagId)) {
|
|
2365
|
+
if (p.openElements.currentTagId !== undefined && TABLE_STRUCTURE_TAGS.has(p.openElements.currentTagId)) {
|
|
2362
2366
|
p.pendingCharacterTokens.length = 0;
|
|
2363
2367
|
p.hasNonWhitespacePendingCharacterToken = false;
|
|
2364
2368
|
p.originalInsertionMode = p.insertionMode;
|
|
@@ -3183,6 +3187,7 @@ function characterInForeignContent(p, token) {
|
|
|
3183
3187
|
}
|
|
3184
3188
|
function popUntilHtmlOrIntegrationPoint(p) {
|
|
3185
3189
|
while (p.treeAdapter.getNamespaceURI(p.openElements.current) !== html_js_1.NS.HTML &&
|
|
3190
|
+
p.openElements.currentTagId !== undefined &&
|
|
3186
3191
|
!p._isIntegrationPoint(p.openElements.currentTagId, p.openElements.current)) {
|
|
3187
3192
|
p.openElements.pop();
|
|
3188
3193
|
}
|
|
@@ -9,10 +9,10 @@ export declare class OpenElementStack<T extends TreeAdapterTypeMap> {
|
|
|
9
9
|
private handler;
|
|
10
10
|
items: T['parentNode'][];
|
|
11
11
|
tagIDs: $[];
|
|
12
|
-
current: T['parentNode'];
|
|
12
|
+
current: T['parentNode'] | undefined;
|
|
13
13
|
stackTop: number;
|
|
14
14
|
tmplCount: number;
|
|
15
|
-
currentTagId:
|
|
15
|
+
currentTagId: number | undefined;
|
|
16
16
|
get currentTmplContentOrNode(): T['parentNode'];
|
|
17
17
|
constructor(document: T['document'], treeAdapter: TreeAdapter<T>, handler: StackHandler<T>);
|
|
18
18
|
private _indexOf;
|
|
@@ -97,14 +97,16 @@ class OpenElementStack {
|
|
|
97
97
|
if (insertionIdx === this.stackTop) {
|
|
98
98
|
this._updateCurrentElement();
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
if (this.current && this.currentTagId !== undefined) {
|
|
101
|
+
this.handler.onItemPush(this.current, this.currentTagId, insertionIdx === this.stackTop);
|
|
102
|
+
}
|
|
101
103
|
}
|
|
102
104
|
popUntilTagNamePopped(tagName) {
|
|
103
105
|
let targetIdx = this.stackTop + 1;
|
|
104
106
|
do {
|
|
105
107
|
targetIdx = this.tagIDs.lastIndexOf(tagName, targetIdx - 1);
|
|
106
108
|
} while (targetIdx > 0 && this.treeAdapter.getNamespaceURI(this.items[targetIdx]) !== html_js_1.NS.HTML);
|
|
107
|
-
this.shortenToLength(targetIdx
|
|
109
|
+
this.shortenToLength(Math.max(targetIdx, 0));
|
|
108
110
|
}
|
|
109
111
|
shortenToLength(idx) {
|
|
110
112
|
while (this.stackTop >= idx) {
|
|
@@ -119,11 +121,11 @@ class OpenElementStack {
|
|
|
119
121
|
}
|
|
120
122
|
popUntilElementPopped(element) {
|
|
121
123
|
const idx = this._indexOf(element);
|
|
122
|
-
this.shortenToLength(idx
|
|
124
|
+
this.shortenToLength(Math.max(idx, 0));
|
|
123
125
|
}
|
|
124
126
|
popUntilPopped(tagNames, targetNS) {
|
|
125
127
|
const idx = this._indexOfTagNames(tagNames, targetNS);
|
|
126
|
-
this.shortenToLength(idx
|
|
128
|
+
this.shortenToLength(Math.max(idx, 0));
|
|
127
129
|
}
|
|
128
130
|
popUntilNumberedHeaderPopped() {
|
|
129
131
|
this.popUntilPopped(html_js_1.NUMBERED_HEADERS, html_js_1.NS.HTML);
|
|
@@ -306,17 +308,19 @@ class OpenElementStack {
|
|
|
306
308
|
}
|
|
307
309
|
//Implied end tags
|
|
308
310
|
generateImpliedEndTags() {
|
|
309
|
-
while (IMPLICIT_END_TAG_REQUIRED.has(this.currentTagId)) {
|
|
311
|
+
while (this.currentTagId !== undefined && IMPLICIT_END_TAG_REQUIRED.has(this.currentTagId)) {
|
|
310
312
|
this.pop();
|
|
311
313
|
}
|
|
312
314
|
}
|
|
313
315
|
generateImpliedEndTagsThoroughly() {
|
|
314
|
-
while (IMPLICIT_END_TAG_REQUIRED_THOROUGHLY.has(this.currentTagId)) {
|
|
316
|
+
while (this.currentTagId !== undefined && IMPLICIT_END_TAG_REQUIRED_THOROUGHLY.has(this.currentTagId)) {
|
|
315
317
|
this.pop();
|
|
316
318
|
}
|
|
317
319
|
}
|
|
318
320
|
generateImpliedEndTagsWithExclusion(exclusionId) {
|
|
319
|
-
while (this.currentTagId !==
|
|
321
|
+
while (this.currentTagId !== undefined &&
|
|
322
|
+
this.currentTagId !== exclusionId &&
|
|
323
|
+
IMPLICIT_END_TAG_REQUIRED_THOROUGHLY.has(this.currentTagId)) {
|
|
320
324
|
this.pop();
|
|
321
325
|
}
|
|
322
326
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.serialize = serialize;
|
|
4
4
|
exports.serializeOuter = serializeOuter;
|
|
5
5
|
const html_js_1 = require("../common/html.js");
|
|
6
|
-
const
|
|
6
|
+
const escape_1 = require("entities/escape");
|
|
7
7
|
const default_js_1 = require("../tree-adapters/default.js");
|
|
8
8
|
// Sets
|
|
9
9
|
const VOID_ELEMENTS = new Set([
|
|
@@ -149,7 +149,7 @@ function serializeAttributes(node, { treeAdapter }) {
|
|
|
149
149
|
else {
|
|
150
150
|
html += attr.name;
|
|
151
151
|
}
|
|
152
|
-
html += `="${(0,
|
|
152
|
+
html += `="${(0, escape_1.escapeAttribute)(attr.value)}"`;
|
|
153
153
|
}
|
|
154
154
|
return html;
|
|
155
155
|
}
|
|
@@ -162,7 +162,7 @@ function serializeTextNode(node, options) {
|
|
|
162
162
|
treeAdapter.getNamespaceURI(parent) === html_js_1.NS.HTML &&
|
|
163
163
|
(0, html_js_1.hasUnescapedText)(parentTn, options.scriptingEnabled)
|
|
164
164
|
? content
|
|
165
|
-
: (0,
|
|
165
|
+
: (0, escape_1.escapeText)(content);
|
|
166
166
|
}
|
|
167
167
|
function serializeCommentNode(node, { treeAdapter }) {
|
|
168
168
|
return `<!--${treeAdapter.getCommentNodeContent(node)}-->`;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Preprocessor } from './preprocessor.js';
|
|
2
2
|
import { type Token, type CharacterToken, type DoctypeToken, type TagToken, type EOFToken, type CommentToken, type Attribute, type Location } from '../common/token.js';
|
|
3
|
-
import { EntityDecoder } from 'entities/
|
|
3
|
+
import { EntityDecoder } from 'entities/decode';
|
|
4
4
|
import { ERR, type ParserErrorHandler } from '../common/error-codes.js';
|
|
5
5
|
declare const enum State {
|
|
6
6
|
DATA = 0,
|
|
@@ -4,7 +4,7 @@ exports.Tokenizer = exports.TokenizerMode = void 0;
|
|
|
4
4
|
const preprocessor_js_1 = require("./preprocessor.js");
|
|
5
5
|
const unicode_js_1 = require("../common/unicode.js");
|
|
6
6
|
const token_js_1 = require("../common/token.js");
|
|
7
|
-
const
|
|
7
|
+
const decode_1 = require("entities/decode");
|
|
8
8
|
const error_codes_js_1 = require("../common/error-codes.js");
|
|
9
9
|
const html_js_1 = require("../common/html.js");
|
|
10
10
|
//States
|
|
@@ -165,7 +165,7 @@ class Tokenizer {
|
|
|
165
165
|
this.currentAttr = { name: '', value: '' };
|
|
166
166
|
this.preprocessor = new preprocessor_js_1.Preprocessor(handler);
|
|
167
167
|
this.currentLocation = this.getCurrentLocation(-1);
|
|
168
|
-
this.entityDecoder = new
|
|
168
|
+
this.entityDecoder = new decode_1.EntityDecoder(decode_1.htmlDecodeTree, (cp, consumed) => {
|
|
169
169
|
// Note: Set `pos` _before_ flushing, as flushing might drop
|
|
170
170
|
// the current chunk and invalidate `entityStartPos`.
|
|
171
171
|
this.preprocessor.pos = this.entityStartPos + consumed - 1;
|
|
@@ -474,7 +474,7 @@ class Tokenizer {
|
|
|
474
474
|
this.returnState = this.state;
|
|
475
475
|
this.state = State.CHARACTER_REFERENCE;
|
|
476
476
|
this.entityStartPos = this.preprocessor.pos;
|
|
477
|
-
this.entityDecoder.startEntity(this._isCharacterReferenceInAttribute() ?
|
|
477
|
+
this.entityDecoder.startEntity(this._isCharacterReferenceInAttribute() ? decode_1.DecodingMode.Attribute : decode_1.DecodingMode.Legacy);
|
|
478
478
|
}
|
|
479
479
|
_isCharacterReferenceInAttribute() {
|
|
480
480
|
return (this.returnState === State.ATTRIBUTE_VALUE_DOUBLE_QUOTED ||
|
|
@@ -81,7 +81,7 @@ export class FormattingElementList {
|
|
|
81
81
|
}
|
|
82
82
|
removeEntry(entry) {
|
|
83
83
|
const entryIndex = this.entries.indexOf(entry);
|
|
84
|
-
if (entryIndex
|
|
84
|
+
if (entryIndex !== -1) {
|
|
85
85
|
this.entries.splice(entryIndex, 1);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -92,11 +92,11 @@ export class FormattingElementList {
|
|
|
92
92
|
*/
|
|
93
93
|
clearToLastMarker() {
|
|
94
94
|
const markerIdx = this.entries.indexOf(MARKER);
|
|
95
|
-
if (markerIdx
|
|
96
|
-
this.entries.
|
|
95
|
+
if (markerIdx === -1) {
|
|
96
|
+
this.entries.length = 0;
|
|
97
97
|
}
|
|
98
98
|
else {
|
|
99
|
-
this.entries.
|
|
99
|
+
this.entries.splice(0, markerIdx + 1);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
//Search
|
package/dist/parser/index.d.ts
CHANGED
|
@@ -122,7 +122,7 @@ export declare class Parser<T extends TreeAdapterTypeMap> implements TokenHandle
|
|
|
122
122
|
onItemPush(node: T['parentNode'], tid: number, isTop: boolean): void;
|
|
123
123
|
/** @internal */
|
|
124
124
|
onItemPop(node: T['parentNode'], isTop: boolean): void;
|
|
125
|
-
protected _setContextModes(current: T['parentNode'], tid: number): void;
|
|
125
|
+
protected _setContextModes(current: T['parentNode'] | undefined, tid: number | undefined): void;
|
|
126
126
|
/** @protected */
|
|
127
127
|
_switchToTextParsing(currentToken: TagToken, nextTokenizerState: (typeof TokenizerMode)[keyof typeof TokenizerMode]): void;
|
|
128
128
|
switchToPlaintextParsing(): void;
|
package/dist/parser/index.js
CHANGED
|
@@ -191,9 +191,10 @@ export class Parser {
|
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
_setContextModes(current, tid) {
|
|
194
|
-
const isHTML = current === this.document || this.treeAdapter.getNamespaceURI(current) === NS.HTML;
|
|
194
|
+
const isHTML = current === this.document || (current && this.treeAdapter.getNamespaceURI(current) === NS.HTML);
|
|
195
195
|
this.currentNotInHTML = !isHTML;
|
|
196
|
-
this.tokenizer.inForeignNode =
|
|
196
|
+
this.tokenizer.inForeignNode =
|
|
197
|
+
!isHTML && current !== undefined && tid !== undefined && !this._isIntegrationPoint(tid, current);
|
|
197
198
|
}
|
|
198
199
|
/** @protected */
|
|
199
200
|
_switchToTextParsing(currentToken, nextTokenizerState) {
|
|
@@ -285,7 +286,7 @@ export class Parser {
|
|
|
285
286
|
}
|
|
286
287
|
else {
|
|
287
288
|
const parent = this.openElements.currentTmplContentOrNode;
|
|
288
|
-
this.treeAdapter.appendChild(parent, element);
|
|
289
|
+
this.treeAdapter.appendChild(parent !== null && parent !== void 0 ? parent : this.document, element);
|
|
289
290
|
}
|
|
290
291
|
}
|
|
291
292
|
/**
|
|
@@ -422,6 +423,7 @@ export class Parser {
|
|
|
422
423
|
// If it _is_ an integration point, then we might have to check that it is not an HTML
|
|
423
424
|
// integration point.
|
|
424
425
|
((token.tagID === $.MGLYPH || token.tagID === $.MALIGNMARK) &&
|
|
426
|
+
currentTagId !== undefined &&
|
|
425
427
|
!this._isIntegrationPoint(currentTagId, current, NS.HTML)));
|
|
426
428
|
}
|
|
427
429
|
/** @protected */
|
|
@@ -474,7 +476,7 @@ export class Parser {
|
|
|
474
476
|
const listLength = this.activeFormattingElements.entries.length;
|
|
475
477
|
if (listLength) {
|
|
476
478
|
const endIndex = this.activeFormattingElements.entries.findIndex((entry) => entry.type === EntryType.Marker || this.openElements.contains(entry.element));
|
|
477
|
-
const unopenIdx = endIndex
|
|
479
|
+
const unopenIdx = endIndex === -1 ? listLength - 1 : endIndex - 1;
|
|
478
480
|
for (let i = unopenIdx; i >= 0; i--) {
|
|
479
481
|
const entry = this.activeFormattingElements.entries[i];
|
|
480
482
|
this._insertElement(entry.token, this.treeAdapter.getNamespaceURI(entry.element));
|
|
@@ -585,7 +587,9 @@ export class Parser {
|
|
|
585
587
|
}
|
|
586
588
|
/** @protected */
|
|
587
589
|
_shouldFosterParentOnInsertion() {
|
|
588
|
-
return this.fosterParentingEnabled &&
|
|
590
|
+
return (this.fosterParentingEnabled &&
|
|
591
|
+
this.openElements.currentTagId !== undefined &&
|
|
592
|
+
this._isElementCausesFosterParenting(this.openElements.currentTagId));
|
|
589
593
|
}
|
|
590
594
|
/** @protected */
|
|
591
595
|
_findFosterParentingLocation() {
|
|
@@ -1204,7 +1208,7 @@ function aaObtainFurthestBlock(p, formattingElementEntry) {
|
|
|
1204
1208
|
}
|
|
1205
1209
|
}
|
|
1206
1210
|
if (!furthestBlock) {
|
|
1207
|
-
p.openElements.shortenToLength(idx
|
|
1211
|
+
p.openElements.shortenToLength(Math.max(idx, 0));
|
|
1208
1212
|
p.activeFormattingElements.removeEntry(formattingElementEntry);
|
|
1209
1213
|
}
|
|
1210
1214
|
return furthestBlock;
|
|
@@ -1690,7 +1694,7 @@ function numberedHeaderStartTagInBody(p, token) {
|
|
|
1690
1694
|
if (p.openElements.hasInButtonScope($.P)) {
|
|
1691
1695
|
p._closePElement();
|
|
1692
1696
|
}
|
|
1693
|
-
if (NUMBERED_HEADERS.has(p.openElements.currentTagId)) {
|
|
1697
|
+
if (p.openElements.currentTagId !== undefined && NUMBERED_HEADERS.has(p.openElements.currentTagId)) {
|
|
1694
1698
|
p.openElements.pop();
|
|
1695
1699
|
}
|
|
1696
1700
|
p._insertElement(token, NS.HTML);
|
|
@@ -2363,7 +2367,7 @@ function eofInText(p, token) {
|
|
|
2363
2367
|
// The "in table" insertion mode
|
|
2364
2368
|
//------------------------------------------------------------------
|
|
2365
2369
|
function characterInTable(p, token) {
|
|
2366
|
-
if (TABLE_STRUCTURE_TAGS.has(p.openElements.currentTagId)) {
|
|
2370
|
+
if (p.openElements.currentTagId !== undefined && TABLE_STRUCTURE_TAGS.has(p.openElements.currentTagId)) {
|
|
2367
2371
|
p.pendingCharacterTokens.length = 0;
|
|
2368
2372
|
p.hasNonWhitespacePendingCharacterToken = false;
|
|
2369
2373
|
p.originalInsertionMode = p.insertionMode;
|
|
@@ -3188,6 +3192,7 @@ function characterInForeignContent(p, token) {
|
|
|
3188
3192
|
}
|
|
3189
3193
|
function popUntilHtmlOrIntegrationPoint(p) {
|
|
3190
3194
|
while (p.treeAdapter.getNamespaceURI(p.openElements.current) !== NS.HTML &&
|
|
3195
|
+
p.openElements.currentTagId !== undefined &&
|
|
3191
3196
|
!p._isIntegrationPoint(p.openElements.currentTagId, p.openElements.current)) {
|
|
3192
3197
|
p.openElements.pop();
|
|
3193
3198
|
}
|
|
@@ -9,10 +9,10 @@ export declare class OpenElementStack<T extends TreeAdapterTypeMap> {
|
|
|
9
9
|
private handler;
|
|
10
10
|
items: T['parentNode'][];
|
|
11
11
|
tagIDs: $[];
|
|
12
|
-
current: T['parentNode'];
|
|
12
|
+
current: T['parentNode'] | undefined;
|
|
13
13
|
stackTop: number;
|
|
14
14
|
tmplCount: number;
|
|
15
|
-
currentTagId:
|
|
15
|
+
currentTagId: number | undefined;
|
|
16
16
|
get currentTmplContentOrNode(): T['parentNode'];
|
|
17
17
|
constructor(document: T['document'], treeAdapter: TreeAdapter<T>, handler: StackHandler<T>);
|
|
18
18
|
private _indexOf;
|
|
@@ -94,14 +94,16 @@ export class OpenElementStack {
|
|
|
94
94
|
if (insertionIdx === this.stackTop) {
|
|
95
95
|
this._updateCurrentElement();
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
if (this.current && this.currentTagId !== undefined) {
|
|
98
|
+
this.handler.onItemPush(this.current, this.currentTagId, insertionIdx === this.stackTop);
|
|
99
|
+
}
|
|
98
100
|
}
|
|
99
101
|
popUntilTagNamePopped(tagName) {
|
|
100
102
|
let targetIdx = this.stackTop + 1;
|
|
101
103
|
do {
|
|
102
104
|
targetIdx = this.tagIDs.lastIndexOf(tagName, targetIdx - 1);
|
|
103
105
|
} while (targetIdx > 0 && this.treeAdapter.getNamespaceURI(this.items[targetIdx]) !== NS.HTML);
|
|
104
|
-
this.shortenToLength(targetIdx
|
|
106
|
+
this.shortenToLength(Math.max(targetIdx, 0));
|
|
105
107
|
}
|
|
106
108
|
shortenToLength(idx) {
|
|
107
109
|
while (this.stackTop >= idx) {
|
|
@@ -116,11 +118,11 @@ export class OpenElementStack {
|
|
|
116
118
|
}
|
|
117
119
|
popUntilElementPopped(element) {
|
|
118
120
|
const idx = this._indexOf(element);
|
|
119
|
-
this.shortenToLength(idx
|
|
121
|
+
this.shortenToLength(Math.max(idx, 0));
|
|
120
122
|
}
|
|
121
123
|
popUntilPopped(tagNames, targetNS) {
|
|
122
124
|
const idx = this._indexOfTagNames(tagNames, targetNS);
|
|
123
|
-
this.shortenToLength(idx
|
|
125
|
+
this.shortenToLength(Math.max(idx, 0));
|
|
124
126
|
}
|
|
125
127
|
popUntilNumberedHeaderPopped() {
|
|
126
128
|
this.popUntilPopped(NUMBERED_HEADERS, NS.HTML);
|
|
@@ -303,17 +305,19 @@ export class OpenElementStack {
|
|
|
303
305
|
}
|
|
304
306
|
//Implied end tags
|
|
305
307
|
generateImpliedEndTags() {
|
|
306
|
-
while (IMPLICIT_END_TAG_REQUIRED.has(this.currentTagId)) {
|
|
308
|
+
while (this.currentTagId !== undefined && IMPLICIT_END_TAG_REQUIRED.has(this.currentTagId)) {
|
|
307
309
|
this.pop();
|
|
308
310
|
}
|
|
309
311
|
}
|
|
310
312
|
generateImpliedEndTagsThoroughly() {
|
|
311
|
-
while (IMPLICIT_END_TAG_REQUIRED_THOROUGHLY.has(this.currentTagId)) {
|
|
313
|
+
while (this.currentTagId !== undefined && IMPLICIT_END_TAG_REQUIRED_THOROUGHLY.has(this.currentTagId)) {
|
|
312
314
|
this.pop();
|
|
313
315
|
}
|
|
314
316
|
}
|
|
315
317
|
generateImpliedEndTagsWithExclusion(exclusionId) {
|
|
316
|
-
while (this.currentTagId !==
|
|
318
|
+
while (this.currentTagId !== undefined &&
|
|
319
|
+
this.currentTagId !== exclusionId &&
|
|
320
|
+
IMPLICIT_END_TAG_REQUIRED_THOROUGHLY.has(this.currentTagId)) {
|
|
317
321
|
this.pop();
|
|
318
322
|
}
|
|
319
323
|
}
|
package/dist/serializer/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TAG_NAMES as $, NS, hasUnescapedText } from '../common/html.js';
|
|
2
|
-
import { escapeText, escapeAttribute } from 'entities/
|
|
2
|
+
import { escapeText, escapeAttribute } from 'entities/escape';
|
|
3
3
|
import { defaultTreeAdapter } from '../tree-adapters/default.js';
|
|
4
4
|
// Sets
|
|
5
5
|
const VOID_ELEMENTS = new Set([
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Preprocessor } from './preprocessor.js';
|
|
2
2
|
import { type Token, type CharacterToken, type DoctypeToken, type TagToken, type EOFToken, type CommentToken, type Attribute, type Location } from '../common/token.js';
|
|
3
|
-
import { EntityDecoder } from 'entities/
|
|
3
|
+
import { EntityDecoder } from 'entities/decode';
|
|
4
4
|
import { ERR, type ParserErrorHandler } from '../common/error-codes.js';
|
|
5
5
|
declare const enum State {
|
|
6
6
|
DATA = 0,
|
package/dist/tokenizer/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Preprocessor } from './preprocessor.js';
|
|
2
2
|
import { CODE_POINTS as $, SEQUENCES as $$, REPLACEMENT_CHARACTER, isSurrogate, isUndefinedCodePoint, isControlCodePoint, } from '../common/unicode.js';
|
|
3
3
|
import { TokenType, getTokenAttr, } from '../common/token.js';
|
|
4
|
-
import { htmlDecodeTree, EntityDecoder, DecodingMode } from 'entities/
|
|
4
|
+
import { htmlDecodeTree, EntityDecoder, DecodingMode } from 'entities/decode';
|
|
5
5
|
import { ERR } from '../common/error-codes.js';
|
|
6
6
|
import { TAG_ID, getTagID } from '../common/html.js';
|
|
7
7
|
//States
|
package/package.json
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"name": "parse5",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "HTML parser and serializer.",
|
|
5
|
-
"version": "7.
|
|
5
|
+
"version": "7.3.0",
|
|
6
6
|
"author": "Ivan Nikulin <ifaaan@gmail.com> (https://github.com/inikulin)",
|
|
7
7
|
"contributors": "https://github.com/inikulin/parse5/graphs/contributors",
|
|
8
8
|
"homepage": "https://parse5.js.org",
|
|
9
9
|
"funding": "https://github.com/inikulin/parse5?sponsor=1",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"entities": "^
|
|
11
|
+
"entities": "^6.0.0"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"html",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"require": "./dist/cjs/index.js"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
|
-
"build:cjs": "tsc --moduleResolution node10 --module CommonJS --target ES6 --outDir dist/cjs && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json"
|
|
39
|
+
"build:cjs": "tsc --noCheck --moduleResolution node10 --module CommonJS --target ES6 --outDir dist/cjs && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json"
|
|
40
40
|
},
|
|
41
41
|
"repository": {
|
|
42
42
|
"type": "git",
|