parse5 7.0.0 → 7.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/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/parser/formatting-element-list.d.ts +6 -1
- package/dist/cjs/parser/formatting-element-list.js +5 -0
- package/dist/cjs/parser/index.js +23 -19
- package/dist/cjs/parser/open-element-stack.d.ts +1 -1
- package/dist/cjs/serializer/index.d.ts +1 -1
- package/dist/cjs/tokenizer/index.d.ts +3 -5
- package/dist/cjs/tokenizer/index.js +26 -40
- package/dist/cjs/tree-adapters/default.d.ts +5 -12
- package/dist/cjs/tree-adapters/default.js +8 -16
- package/dist/common/error-codes.js +1 -1
- package/dist/common/html.js +5 -5
- package/dist/common/token.js +1 -1
- package/dist/common/unicode.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/parser/formatting-element-list.d.ts +6 -1
- package/dist/parser/formatting-element-list.js +6 -1
- package/dist/parser/index.js +23 -19
- package/dist/parser/open-element-stack.d.ts +1 -1
- package/dist/serializer/index.d.ts +1 -1
- package/dist/tokenizer/index.d.ts +3 -5
- package/dist/tokenizer/index.js +26 -40
- package/dist/tree-adapters/default.d.ts +5 -12
- package/dist/tree-adapters/default.js +7 -15
- package/package.json +4 -4
- package/dist/cjs/package.json +0 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare function parse<T extends TreeAdapterTypeMap = DefaultTreeAdapterM
|
|
|
45
45
|
* console.log(documentFragment.childNodes[0].tagName); //> 'table'
|
|
46
46
|
*
|
|
47
47
|
* // Parses the html fragment in the context of the parsed <table> element.
|
|
48
|
-
* const trFragment =
|
|
48
|
+
* const trFragment = parse5.parseFragment(documentFragment.childNodes[0], '<tr><td>Shake it, baby</td></tr>');
|
|
49
49
|
*
|
|
50
50
|
* console.log(trFragment.childNodes[0].childNodes[0].tagName); //> 'td'
|
|
51
51
|
* ```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TagToken } from '../common/token.js';
|
|
2
|
-
import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface';
|
|
2
|
+
import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface.js';
|
|
3
3
|
export declare enum EntryType {
|
|
4
4
|
Marker = 0,
|
|
5
5
|
Element = 1
|
|
@@ -24,6 +24,11 @@ export declare class FormattingElementList<T extends TreeAdapterTypeMap> {
|
|
|
24
24
|
pushElement(element: T['element'], token: TagToken): void;
|
|
25
25
|
insertElementAfterBookmark(element: T['element'], token: TagToken): void;
|
|
26
26
|
removeEntry(entry: Entry<T>): void;
|
|
27
|
+
/**
|
|
28
|
+
* Clears the list of formatting elements up to the last marker.
|
|
29
|
+
*
|
|
30
|
+
* @see https://html.spec.whatwg.org/multipage/parsing.html#clear-the-list-of-active-formatting-elements-up-to-the-last-marker
|
|
31
|
+
*/
|
|
27
32
|
clearToLastMarker(): void;
|
|
28
33
|
getElementEntryInScopeWithTagName(tagName: string): ElementEntry<T> | null;
|
|
29
34
|
getElementEntry(element: T['element']): ElementEntry<T> | undefined;
|
|
@@ -88,6 +88,11 @@ class FormattingElementList {
|
|
|
88
88
|
this.entries.splice(entryIndex, 1);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Clears the list of formatting elements up to the last marker.
|
|
93
|
+
*
|
|
94
|
+
* @see https://html.spec.whatwg.org/multipage/parsing.html#clear-the-list-of-active-formatting-elements-up-to-the-last-marker
|
|
95
|
+
*/
|
|
91
96
|
clearToLastMarker() {
|
|
92
97
|
const markerIdx = this.entries.indexOf(MARKER);
|
|
93
98
|
if (markerIdx >= 0) {
|
package/dist/cjs/parser/index.js
CHANGED
|
@@ -1307,19 +1307,7 @@ function endTagInHead(p, token) {
|
|
|
1307
1307
|
break;
|
|
1308
1308
|
}
|
|
1309
1309
|
case html_js_1.TAG_ID.TEMPLATE: {
|
|
1310
|
-
|
|
1311
|
-
p.openElements.generateImpliedEndTagsThoroughly();
|
|
1312
|
-
if (p.openElements.currentTagId !== html_js_1.TAG_ID.TEMPLATE) {
|
|
1313
|
-
p._err(token, error_codes_js_1.ERR.closingOfElementWithOpenChildElements);
|
|
1314
|
-
}
|
|
1315
|
-
p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.TEMPLATE);
|
|
1316
|
-
p.activeFormattingElements.clearToLastMarker();
|
|
1317
|
-
p.tmplInsertionModeStack.shift();
|
|
1318
|
-
p._resetInsertionMode();
|
|
1319
|
-
}
|
|
1320
|
-
else {
|
|
1321
|
-
p._err(token, error_codes_js_1.ERR.endTagWithoutMatchingOpenElement);
|
|
1322
|
-
}
|
|
1310
|
+
templateEndTagInHead(p, token);
|
|
1323
1311
|
break;
|
|
1324
1312
|
}
|
|
1325
1313
|
default: {
|
|
@@ -1327,6 +1315,21 @@ function endTagInHead(p, token) {
|
|
|
1327
1315
|
}
|
|
1328
1316
|
}
|
|
1329
1317
|
}
|
|
1318
|
+
function templateEndTagInHead(p, token) {
|
|
1319
|
+
if (p.openElements.tmplCount > 0) {
|
|
1320
|
+
p.openElements.generateImpliedEndTagsThoroughly();
|
|
1321
|
+
if (p.openElements.currentTagId !== html_js_1.TAG_ID.TEMPLATE) {
|
|
1322
|
+
p._err(token, error_codes_js_1.ERR.closingOfElementWithOpenChildElements);
|
|
1323
|
+
}
|
|
1324
|
+
p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.TEMPLATE);
|
|
1325
|
+
p.activeFormattingElements.clearToLastMarker();
|
|
1326
|
+
p.tmplInsertionModeStack.shift();
|
|
1327
|
+
p._resetInsertionMode();
|
|
1328
|
+
}
|
|
1329
|
+
else {
|
|
1330
|
+
p._err(token, error_codes_js_1.ERR.endTagWithoutMatchingOpenElement);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1330
1333
|
function tokenInHead(p, token) {
|
|
1331
1334
|
p.openElements.pop();
|
|
1332
1335
|
p.insertionMode = InsertionMode.AFTER_HEAD;
|
|
@@ -1435,7 +1438,7 @@ function endTagAfterHead(p, token) {
|
|
|
1435
1438
|
break;
|
|
1436
1439
|
}
|
|
1437
1440
|
case html_js_1.TAG_ID.TEMPLATE: {
|
|
1438
|
-
|
|
1441
|
+
templateEndTagInHead(p, token);
|
|
1439
1442
|
break;
|
|
1440
1443
|
}
|
|
1441
1444
|
default: {
|
|
@@ -2095,6 +2098,7 @@ function endTagInBody(p, token) {
|
|
|
2095
2098
|
case html_js_1.TAG_ID.MAIN:
|
|
2096
2099
|
case html_js_1.TAG_ID.MENU:
|
|
2097
2100
|
case html_js_1.TAG_ID.ASIDE:
|
|
2101
|
+
case html_js_1.TAG_ID.BUTTON:
|
|
2098
2102
|
case html_js_1.TAG_ID.CENTER:
|
|
2099
2103
|
case html_js_1.TAG_ID.FIGURE:
|
|
2100
2104
|
case html_js_1.TAG_ID.FOOTER:
|
|
@@ -2154,7 +2158,7 @@ function endTagInBody(p, token) {
|
|
|
2154
2158
|
break;
|
|
2155
2159
|
}
|
|
2156
2160
|
case html_js_1.TAG_ID.TEMPLATE: {
|
|
2157
|
-
|
|
2161
|
+
templateEndTagInHead(p, token);
|
|
2158
2162
|
break;
|
|
2159
2163
|
}
|
|
2160
2164
|
default: {
|
|
@@ -2320,7 +2324,7 @@ function endTagInTable(p, token) {
|
|
|
2320
2324
|
break;
|
|
2321
2325
|
}
|
|
2322
2326
|
case html_js_1.TAG_ID.TEMPLATE: {
|
|
2323
|
-
|
|
2327
|
+
templateEndTagInHead(p, token);
|
|
2324
2328
|
break;
|
|
2325
2329
|
}
|
|
2326
2330
|
case html_js_1.TAG_ID.BODY:
|
|
@@ -2457,7 +2461,7 @@ function endTagInColumnGroup(p, token) {
|
|
|
2457
2461
|
break;
|
|
2458
2462
|
}
|
|
2459
2463
|
case html_js_1.TAG_ID.TEMPLATE: {
|
|
2460
|
-
|
|
2464
|
+
templateEndTagInHead(p, token);
|
|
2461
2465
|
break;
|
|
2462
2466
|
}
|
|
2463
2467
|
case html_js_1.TAG_ID.COL: {
|
|
@@ -2752,7 +2756,7 @@ function endTagInSelect(p, token) {
|
|
|
2752
2756
|
break;
|
|
2753
2757
|
}
|
|
2754
2758
|
case html_js_1.TAG_ID.TEMPLATE: {
|
|
2755
|
-
|
|
2759
|
+
templateEndTagInHead(p, token);
|
|
2756
2760
|
break;
|
|
2757
2761
|
}
|
|
2758
2762
|
default:
|
|
@@ -2850,7 +2854,7 @@ function startTagInTemplate(p, token) {
|
|
|
2850
2854
|
}
|
|
2851
2855
|
function endTagInTemplate(p, token) {
|
|
2852
2856
|
if (token.tagID === html_js_1.TAG_ID.TEMPLATE) {
|
|
2853
|
-
|
|
2857
|
+
templateEndTagInHead(p, token);
|
|
2854
2858
|
}
|
|
2855
2859
|
}
|
|
2856
2860
|
function eofInTemplate(p, token) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TAG_ID as $ } from '../common/html.js';
|
|
2
|
-
import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface';
|
|
2
|
+
import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface.js';
|
|
3
3
|
export interface StackHandler<T extends TreeAdapterTypeMap> {
|
|
4
4
|
onItemPush: (node: T['parentNode'], tid: number, isTop: boolean) => void;
|
|
5
5
|
onItemPop: (node: T['parentNode'], isTop: boolean) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface';
|
|
1
|
+
import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface.js';
|
|
2
2
|
import { type DefaultTreeAdapterMap } from '../tree-adapters/default.js';
|
|
3
3
|
export interface SerializerOptions<T extends TreeAdapterTypeMap> {
|
|
4
4
|
/**
|
|
@@ -78,10 +78,9 @@ declare const enum State {
|
|
|
78
78
|
AMBIGUOUS_AMPERSAND = 73,
|
|
79
79
|
NUMERIC_CHARACTER_REFERENCE = 74,
|
|
80
80
|
HEXADEMICAL_CHARACTER_REFERENCE_START = 75,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
NUMERIC_CHARACTER_REFERENCE_END = 79
|
|
81
|
+
HEXADEMICAL_CHARACTER_REFERENCE = 76,
|
|
82
|
+
DECIMAL_CHARACTER_REFERENCE = 77,
|
|
83
|
+
NUMERIC_CHARACTER_REFERENCE_END = 78
|
|
85
84
|
}
|
|
86
85
|
export declare const TokenizerMode: {
|
|
87
86
|
readonly DATA: State.DATA;
|
|
@@ -241,7 +240,6 @@ export declare class Tokenizer {
|
|
|
241
240
|
private _stateAmbiguousAmpersand;
|
|
242
241
|
private _stateNumericCharacterReference;
|
|
243
242
|
private _stateHexademicalCharacterReferenceStart;
|
|
244
|
-
private _stateDecimalCharacterReferenceStart;
|
|
245
243
|
private _stateHexademicalCharacterReference;
|
|
246
244
|
private _stateDecimalCharacterReference;
|
|
247
245
|
private _stateNumericCharacterReferenceEnd;
|
|
@@ -116,10 +116,9 @@ var State;
|
|
|
116
116
|
State[State["AMBIGUOUS_AMPERSAND"] = 73] = "AMBIGUOUS_AMPERSAND";
|
|
117
117
|
State[State["NUMERIC_CHARACTER_REFERENCE"] = 74] = "NUMERIC_CHARACTER_REFERENCE";
|
|
118
118
|
State[State["HEXADEMICAL_CHARACTER_REFERENCE_START"] = 75] = "HEXADEMICAL_CHARACTER_REFERENCE_START";
|
|
119
|
-
State[State["
|
|
120
|
-
State[State["
|
|
121
|
-
State[State["
|
|
122
|
-
State[State["NUMERIC_CHARACTER_REFERENCE_END"] = 79] = "NUMERIC_CHARACTER_REFERENCE_END";
|
|
119
|
+
State[State["HEXADEMICAL_CHARACTER_REFERENCE"] = 76] = "HEXADEMICAL_CHARACTER_REFERENCE";
|
|
120
|
+
State[State["DECIMAL_CHARACTER_REFERENCE"] = 77] = "DECIMAL_CHARACTER_REFERENCE";
|
|
121
|
+
State[State["NUMERIC_CHARACTER_REFERENCE_END"] = 78] = "NUMERIC_CHARACTER_REFERENCE_END";
|
|
123
122
|
})(State || (State = {}));
|
|
124
123
|
//Tokenizer initial states for different modes
|
|
125
124
|
exports.TokenizerMode = {
|
|
@@ -277,9 +276,9 @@ class Tokenizer {
|
|
|
277
276
|
this.consumedAfterSnapshot -= count;
|
|
278
277
|
this.preprocessor.retreat(count);
|
|
279
278
|
}
|
|
280
|
-
_reconsumeInState(state) {
|
|
279
|
+
_reconsumeInState(state, cp) {
|
|
281
280
|
this.state = state;
|
|
282
|
-
this.
|
|
281
|
+
this._callState(cp);
|
|
283
282
|
}
|
|
284
283
|
_advanceBy(count) {
|
|
285
284
|
this.consumedAfterSnapshot += count;
|
|
@@ -475,13 +474,11 @@ class Tokenizer {
|
|
|
475
474
|
this._createCharacterToken(type, ch);
|
|
476
475
|
}
|
|
477
476
|
_emitCodePoint(cp) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
type = token_js_1.TokenType.NULL_CHARACTER;
|
|
484
|
-
}
|
|
477
|
+
const type = isWhitespace(cp)
|
|
478
|
+
? token_js_1.TokenType.WHITESPACE_CHARACTER
|
|
479
|
+
: cp === unicode_js_1.CODE_POINTS.NULL
|
|
480
|
+
? token_js_1.TokenType.NULL_CHARACTER
|
|
481
|
+
: token_js_1.TokenType.CHARACTER;
|
|
485
482
|
this._appendCharToCurrentCharacterToken(type, String.fromCodePoint(cp));
|
|
486
483
|
}
|
|
487
484
|
//NOTE: used when we emit characters explicitly.
|
|
@@ -864,10 +861,6 @@ class Tokenizer {
|
|
|
864
861
|
this._stateHexademicalCharacterReferenceStart(cp);
|
|
865
862
|
break;
|
|
866
863
|
}
|
|
867
|
-
case State.DECIMAL_CHARACTER_REFERENCE_START: {
|
|
868
|
-
this._stateDecimalCharacterReferenceStart(cp);
|
|
869
|
-
break;
|
|
870
|
-
}
|
|
871
864
|
case State.HEXADEMICAL_CHARACTER_REFERENCE: {
|
|
872
865
|
this._stateHexademicalCharacterReference(cp);
|
|
873
866
|
break;
|
|
@@ -877,7 +870,7 @@ class Tokenizer {
|
|
|
877
870
|
break;
|
|
878
871
|
}
|
|
879
872
|
case State.NUMERIC_CHARACTER_REFERENCE_END: {
|
|
880
|
-
this._stateNumericCharacterReferenceEnd();
|
|
873
|
+
this._stateNumericCharacterReferenceEnd(cp);
|
|
881
874
|
break;
|
|
882
875
|
}
|
|
883
876
|
default: {
|
|
@@ -2775,7 +2768,7 @@ class Tokenizer {
|
|
|
2775
2768
|
}
|
|
2776
2769
|
else {
|
|
2777
2770
|
this._flushCodePointConsumedAsCharacterReference(unicode_js_1.CODE_POINTS.AMPERSAND);
|
|
2778
|
-
this._reconsumeInState(this.returnState);
|
|
2771
|
+
this._reconsumeInState(this.returnState, cp);
|
|
2779
2772
|
}
|
|
2780
2773
|
}
|
|
2781
2774
|
// Named character reference state
|
|
@@ -2808,7 +2801,7 @@ class Tokenizer {
|
|
|
2808
2801
|
if (cp === unicode_js_1.CODE_POINTS.SEMICOLON) {
|
|
2809
2802
|
this._err(error_codes_js_1.ERR.unknownNamedCharacterReference);
|
|
2810
2803
|
}
|
|
2811
|
-
this._reconsumeInState(this.returnState);
|
|
2804
|
+
this._reconsumeInState(this.returnState, cp);
|
|
2812
2805
|
}
|
|
2813
2806
|
}
|
|
2814
2807
|
// Numeric character reference state
|
|
@@ -2818,9 +2811,16 @@ class Tokenizer {
|
|
|
2818
2811
|
if (cp === unicode_js_1.CODE_POINTS.LATIN_SMALL_X || cp === unicode_js_1.CODE_POINTS.LATIN_CAPITAL_X) {
|
|
2819
2812
|
this.state = State.HEXADEMICAL_CHARACTER_REFERENCE_START;
|
|
2820
2813
|
}
|
|
2814
|
+
// Inlined decimal character reference start state
|
|
2815
|
+
else if (isAsciiDigit(cp)) {
|
|
2816
|
+
this.state = State.DECIMAL_CHARACTER_REFERENCE;
|
|
2817
|
+
this._stateDecimalCharacterReference(cp);
|
|
2818
|
+
}
|
|
2821
2819
|
else {
|
|
2822
|
-
this.
|
|
2823
|
-
this.
|
|
2820
|
+
this._err(error_codes_js_1.ERR.absenceOfDigitsInNumericCharacterReference);
|
|
2821
|
+
this._flushCodePointConsumedAsCharacterReference(unicode_js_1.CODE_POINTS.AMPERSAND);
|
|
2822
|
+
this._flushCodePointConsumedAsCharacterReference(unicode_js_1.CODE_POINTS.NUMBER_SIGN);
|
|
2823
|
+
this._reconsumeInState(this.returnState, cp);
|
|
2824
2824
|
}
|
|
2825
2825
|
}
|
|
2826
2826
|
// Hexademical character reference start state
|
|
@@ -2838,20 +2838,6 @@ class Tokenizer {
|
|
|
2838
2838
|
this.state = this.returnState;
|
|
2839
2839
|
}
|
|
2840
2840
|
}
|
|
2841
|
-
// Decimal character reference start state
|
|
2842
|
-
//------------------------------------------------------------------
|
|
2843
|
-
_stateDecimalCharacterReferenceStart(cp) {
|
|
2844
|
-
if (isAsciiDigit(cp)) {
|
|
2845
|
-
this.state = State.DECIMAL_CHARACTER_REFERENCE;
|
|
2846
|
-
this._stateDecimalCharacterReference(cp);
|
|
2847
|
-
}
|
|
2848
|
-
else {
|
|
2849
|
-
this._err(error_codes_js_1.ERR.absenceOfDigitsInNumericCharacterReference);
|
|
2850
|
-
this._flushCodePointConsumedAsCharacterReference(unicode_js_1.CODE_POINTS.AMPERSAND);
|
|
2851
|
-
this._flushCodePointConsumedAsCharacterReference(unicode_js_1.CODE_POINTS.NUMBER_SIGN);
|
|
2852
|
-
this._reconsumeInState(this.returnState);
|
|
2853
|
-
}
|
|
2854
|
-
}
|
|
2855
2841
|
// Hexademical character reference state
|
|
2856
2842
|
//------------------------------------------------------------------
|
|
2857
2843
|
_stateHexademicalCharacterReference(cp) {
|
|
@@ -2870,7 +2856,7 @@ class Tokenizer {
|
|
|
2870
2856
|
else {
|
|
2871
2857
|
this._err(error_codes_js_1.ERR.missingSemicolonAfterCharacterReference);
|
|
2872
2858
|
this.state = State.NUMERIC_CHARACTER_REFERENCE_END;
|
|
2873
|
-
this._stateNumericCharacterReferenceEnd();
|
|
2859
|
+
this._stateNumericCharacterReferenceEnd(cp);
|
|
2874
2860
|
}
|
|
2875
2861
|
}
|
|
2876
2862
|
// Decimal character reference state
|
|
@@ -2885,12 +2871,12 @@ class Tokenizer {
|
|
|
2885
2871
|
else {
|
|
2886
2872
|
this._err(error_codes_js_1.ERR.missingSemicolonAfterCharacterReference);
|
|
2887
2873
|
this.state = State.NUMERIC_CHARACTER_REFERENCE_END;
|
|
2888
|
-
this._stateNumericCharacterReferenceEnd();
|
|
2874
|
+
this._stateNumericCharacterReferenceEnd(cp);
|
|
2889
2875
|
}
|
|
2890
2876
|
}
|
|
2891
2877
|
// Numeric character reference end state
|
|
2892
2878
|
//------------------------------------------------------------------
|
|
2893
|
-
_stateNumericCharacterReferenceEnd() {
|
|
2879
|
+
_stateNumericCharacterReferenceEnd(cp) {
|
|
2894
2880
|
if (this.charRefCode === unicode_js_1.CODE_POINTS.NULL) {
|
|
2895
2881
|
this._err(error_codes_js_1.ERR.nullCharacterReference);
|
|
2896
2882
|
this.charRefCode = unicode_js_1.CODE_POINTS.REPLACEMENT_CHARACTER;
|
|
@@ -2914,7 +2900,7 @@ class Tokenizer {
|
|
|
2914
2900
|
}
|
|
2915
2901
|
}
|
|
2916
2902
|
this._flushCodePointConsumedAsCharacterReference(this.charRefCode);
|
|
2917
|
-
this._reconsumeInState(this.returnState);
|
|
2903
|
+
this._reconsumeInState(this.returnState, cp);
|
|
2918
2904
|
}
|
|
2919
2905
|
}
|
|
2920
2906
|
exports.Tokenizer = Tokenizer;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { DOCUMENT_MODE, type NS } from '../common/html.js';
|
|
2
2
|
import type { Attribute, Location, ElementLocation } from '../common/token.js';
|
|
3
3
|
import type { TreeAdapter, TreeAdapterTypeMap } from './interface.js';
|
|
4
|
-
export declare enum NodeType {
|
|
5
|
-
Document = "#document",
|
|
6
|
-
DocumentFragment = "#document-fragment",
|
|
7
|
-
Comment = "#comment",
|
|
8
|
-
Text = "#text",
|
|
9
|
-
DocumentType = "#documentType"
|
|
10
|
-
}
|
|
11
4
|
export interface Document {
|
|
12
5
|
/** The name of the node. */
|
|
13
|
-
nodeName:
|
|
6
|
+
nodeName: '#document';
|
|
14
7
|
/**
|
|
15
8
|
* Document mode.
|
|
16
9
|
*
|
|
@@ -23,7 +16,7 @@ export interface Document {
|
|
|
23
16
|
}
|
|
24
17
|
export interface DocumentFragment {
|
|
25
18
|
/** The name of the node. */
|
|
26
|
-
nodeName:
|
|
19
|
+
nodeName: '#document-fragment';
|
|
27
20
|
/** The node's children. */
|
|
28
21
|
childNodes: ChildNode[];
|
|
29
22
|
/** Comment source code location info. Available if location info is enabled. */
|
|
@@ -47,7 +40,7 @@ export interface Element {
|
|
|
47
40
|
}
|
|
48
41
|
export interface CommentNode {
|
|
49
42
|
/** The name of the node. */
|
|
50
|
-
nodeName:
|
|
43
|
+
nodeName: '#comment';
|
|
51
44
|
/** Parent node. */
|
|
52
45
|
parentNode: ParentNode | null;
|
|
53
46
|
/** Comment text. */
|
|
@@ -56,7 +49,7 @@ export interface CommentNode {
|
|
|
56
49
|
sourceCodeLocation?: Location | null;
|
|
57
50
|
}
|
|
58
51
|
export interface TextNode {
|
|
59
|
-
nodeName:
|
|
52
|
+
nodeName: '#text';
|
|
60
53
|
/** Parent node. */
|
|
61
54
|
parentNode: ParentNode | null;
|
|
62
55
|
/** Text content. */
|
|
@@ -72,7 +65,7 @@ export interface Template extends Element {
|
|
|
72
65
|
}
|
|
73
66
|
export interface DocumentType {
|
|
74
67
|
/** The name of the node. */
|
|
75
|
-
nodeName:
|
|
68
|
+
nodeName: '#documentType';
|
|
76
69
|
/** Parent node. */
|
|
77
70
|
parentNode: ParentNode | null;
|
|
78
71
|
/** Document type name. */
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultTreeAdapter =
|
|
3
|
+
exports.defaultTreeAdapter = void 0;
|
|
4
4
|
const html_js_1 = require("../common/html.js");
|
|
5
|
-
var NodeType;
|
|
6
|
-
(function (NodeType) {
|
|
7
|
-
NodeType["Document"] = "#document";
|
|
8
|
-
NodeType["DocumentFragment"] = "#document-fragment";
|
|
9
|
-
NodeType["Comment"] = "#comment";
|
|
10
|
-
NodeType["Text"] = "#text";
|
|
11
|
-
NodeType["DocumentType"] = "#documentType";
|
|
12
|
-
})(NodeType = exports.NodeType || (exports.NodeType = {}));
|
|
13
5
|
function createTextNode(value) {
|
|
14
6
|
return {
|
|
15
|
-
nodeName:
|
|
7
|
+
nodeName: '#text',
|
|
16
8
|
value,
|
|
17
9
|
parentNode: null,
|
|
18
10
|
};
|
|
@@ -21,14 +13,14 @@ exports.defaultTreeAdapter = {
|
|
|
21
13
|
//Node construction
|
|
22
14
|
createDocument() {
|
|
23
15
|
return {
|
|
24
|
-
nodeName:
|
|
16
|
+
nodeName: '#document',
|
|
25
17
|
mode: html_js_1.DOCUMENT_MODE.NO_QUIRKS,
|
|
26
18
|
childNodes: [],
|
|
27
19
|
};
|
|
28
20
|
},
|
|
29
21
|
createDocumentFragment() {
|
|
30
22
|
return {
|
|
31
|
-
nodeName:
|
|
23
|
+
nodeName: '#document-fragment',
|
|
32
24
|
childNodes: [],
|
|
33
25
|
};
|
|
34
26
|
},
|
|
@@ -44,7 +36,7 @@ exports.defaultTreeAdapter = {
|
|
|
44
36
|
},
|
|
45
37
|
createCommentNode(data) {
|
|
46
38
|
return {
|
|
47
|
-
nodeName:
|
|
39
|
+
nodeName: '#comment',
|
|
48
40
|
data,
|
|
49
41
|
parentNode: null,
|
|
50
42
|
};
|
|
@@ -66,7 +58,7 @@ exports.defaultTreeAdapter = {
|
|
|
66
58
|
return templateElement.content;
|
|
67
59
|
},
|
|
68
60
|
setDocumentType(document, name, publicId, systemId) {
|
|
69
|
-
const doctypeNode = document.childNodes.find((node) => node.nodeName ===
|
|
61
|
+
const doctypeNode = document.childNodes.find((node) => node.nodeName === '#documentType');
|
|
70
62
|
if (doctypeNode) {
|
|
71
63
|
doctypeNode.name = name;
|
|
72
64
|
doctypeNode.publicId = publicId;
|
|
@@ -74,7 +66,7 @@ exports.defaultTreeAdapter = {
|
|
|
74
66
|
}
|
|
75
67
|
else {
|
|
76
68
|
const node = {
|
|
77
|
-
nodeName:
|
|
69
|
+
nodeName: '#documentType',
|
|
78
70
|
name,
|
|
79
71
|
publicId,
|
|
80
72
|
systemId,
|
|
@@ -166,7 +158,7 @@ exports.defaultTreeAdapter = {
|
|
|
166
158
|
return node.nodeName === '#comment';
|
|
167
159
|
},
|
|
168
160
|
isDocumentTypeNode(node) {
|
|
169
|
-
return node.nodeName ===
|
|
161
|
+
return node.nodeName === '#documentType';
|
|
170
162
|
},
|
|
171
163
|
isElementNode(node) {
|
|
172
164
|
return Object.prototype.hasOwnProperty.call(node, 'tagName');
|
|
@@ -60,5 +60,5 @@ export var ERR;
|
|
|
60
60
|
ERR["misplacedStartTagForHeadElement"] = "misplaced-start-tag-for-head-element";
|
|
61
61
|
ERR["nestedNoscriptInHead"] = "nested-noscript-in-head";
|
|
62
62
|
ERR["eofInElementThatCanContainOnlyText"] = "eof-in-element-that-can-contain-only-text";
|
|
63
|
-
})(ERR || (ERR = {}));
|
|
63
|
+
})(ERR = ERR || (ERR = {}));
|
|
64
64
|
//# sourceMappingURL=error-codes.js.map
|
package/dist/common/html.js
CHANGED
|
@@ -7,7 +7,7 @@ export var NS;
|
|
|
7
7
|
NS["XLINK"] = "http://www.w3.org/1999/xlink";
|
|
8
8
|
NS["XML"] = "http://www.w3.org/XML/1998/namespace";
|
|
9
9
|
NS["XMLNS"] = "http://www.w3.org/2000/xmlns/";
|
|
10
|
-
})(NS || (NS = {}));
|
|
10
|
+
})(NS = NS || (NS = {}));
|
|
11
11
|
export var ATTRS;
|
|
12
12
|
(function (ATTRS) {
|
|
13
13
|
ATTRS["TYPE"] = "type";
|
|
@@ -18,7 +18,7 @@ export var ATTRS;
|
|
|
18
18
|
ATTRS["COLOR"] = "color";
|
|
19
19
|
ATTRS["FACE"] = "face";
|
|
20
20
|
ATTRS["SIZE"] = "size";
|
|
21
|
-
})(ATTRS || (ATTRS = {}));
|
|
21
|
+
})(ATTRS = ATTRS || (ATTRS = {}));
|
|
22
22
|
/**
|
|
23
23
|
* The mode of the document.
|
|
24
24
|
*
|
|
@@ -29,7 +29,7 @@ export var DOCUMENT_MODE;
|
|
|
29
29
|
DOCUMENT_MODE["NO_QUIRKS"] = "no-quirks";
|
|
30
30
|
DOCUMENT_MODE["QUIRKS"] = "quirks";
|
|
31
31
|
DOCUMENT_MODE["LIMITED_QUIRKS"] = "limited-quirks";
|
|
32
|
-
})(DOCUMENT_MODE || (DOCUMENT_MODE = {}));
|
|
32
|
+
})(DOCUMENT_MODE = DOCUMENT_MODE || (DOCUMENT_MODE = {}));
|
|
33
33
|
export var TAG_NAMES;
|
|
34
34
|
(function (TAG_NAMES) {
|
|
35
35
|
TAG_NAMES["A"] = "a";
|
|
@@ -154,7 +154,7 @@ export var TAG_NAMES;
|
|
|
154
154
|
TAG_NAMES["VAR"] = "var";
|
|
155
155
|
TAG_NAMES["WBR"] = "wbr";
|
|
156
156
|
TAG_NAMES["XMP"] = "xmp";
|
|
157
|
-
})(TAG_NAMES || (TAG_NAMES = {}));
|
|
157
|
+
})(TAG_NAMES = TAG_NAMES || (TAG_NAMES = {}));
|
|
158
158
|
/**
|
|
159
159
|
* Tag IDs are numeric IDs for known tag names.
|
|
160
160
|
*
|
|
@@ -285,7 +285,7 @@ export var TAG_ID;
|
|
|
285
285
|
TAG_ID[TAG_ID["VAR"] = 120] = "VAR";
|
|
286
286
|
TAG_ID[TAG_ID["WBR"] = 121] = "WBR";
|
|
287
287
|
TAG_ID[TAG_ID["XMP"] = 122] = "XMP";
|
|
288
|
-
})(TAG_ID || (TAG_ID = {}));
|
|
288
|
+
})(TAG_ID = TAG_ID || (TAG_ID = {}));
|
|
289
289
|
const TAG_NAME_TO_ID = new Map([
|
|
290
290
|
[TAG_NAMES.A, TAG_ID.A],
|
|
291
291
|
[TAG_NAMES.ADDRESS, TAG_ID.ADDRESS],
|
package/dist/common/token.js
CHANGED
|
@@ -9,7 +9,7 @@ export var TokenType;
|
|
|
9
9
|
TokenType[TokenType["DOCTYPE"] = 6] = "DOCTYPE";
|
|
10
10
|
TokenType[TokenType["EOF"] = 7] = "EOF";
|
|
11
11
|
TokenType[TokenType["HIBERNATION"] = 8] = "HIBERNATION";
|
|
12
|
-
})(TokenType || (TokenType = {}));
|
|
12
|
+
})(TokenType = TokenType || (TokenType = {}));
|
|
13
13
|
export function getTokenAttr(token, attrName) {
|
|
14
14
|
for (let i = token.attrs.length - 1; i >= 0; i--) {
|
|
15
15
|
if (token.attrs[i].name === attrName) {
|
package/dist/common/unicode.js
CHANGED
|
@@ -39,7 +39,7 @@ export var CODE_POINTS;
|
|
|
39
39
|
CODE_POINTS[CODE_POINTS["LATIN_SMALL_X"] = 120] = "LATIN_SMALL_X";
|
|
40
40
|
CODE_POINTS[CODE_POINTS["LATIN_SMALL_Z"] = 122] = "LATIN_SMALL_Z";
|
|
41
41
|
CODE_POINTS[CODE_POINTS["REPLACEMENT_CHARACTER"] = 65533] = "REPLACEMENT_CHARACTER";
|
|
42
|
-
})(CODE_POINTS || (CODE_POINTS = {}));
|
|
42
|
+
})(CODE_POINTS = CODE_POINTS || (CODE_POINTS = {}));
|
|
43
43
|
export const SEQUENCES = {
|
|
44
44
|
DASH_DASH: '--',
|
|
45
45
|
CDATA_START: '[CDATA[',
|
package/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare function parse<T extends TreeAdapterTypeMap = DefaultTreeAdapterM
|
|
|
45
45
|
* console.log(documentFragment.childNodes[0].tagName); //> 'table'
|
|
46
46
|
*
|
|
47
47
|
* // Parses the html fragment in the context of the parsed <table> element.
|
|
48
|
-
* const trFragment =
|
|
48
|
+
* const trFragment = parse5.parseFragment(documentFragment.childNodes[0], '<tr><td>Shake it, baby</td></tr>');
|
|
49
49
|
*
|
|
50
50
|
* console.log(trFragment.childNodes[0].childNodes[0].tagName); //> 'td'
|
|
51
51
|
* ```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TagToken } from '../common/token.js';
|
|
2
|
-
import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface';
|
|
2
|
+
import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface.js';
|
|
3
3
|
export declare enum EntryType {
|
|
4
4
|
Marker = 0,
|
|
5
5
|
Element = 1
|
|
@@ -24,6 +24,11 @@ export declare class FormattingElementList<T extends TreeAdapterTypeMap> {
|
|
|
24
24
|
pushElement(element: T['element'], token: TagToken): void;
|
|
25
25
|
insertElementAfterBookmark(element: T['element'], token: TagToken): void;
|
|
26
26
|
removeEntry(entry: Entry<T>): void;
|
|
27
|
+
/**
|
|
28
|
+
* Clears the list of formatting elements up to the last marker.
|
|
29
|
+
*
|
|
30
|
+
* @see https://html.spec.whatwg.org/multipage/parsing.html#clear-the-list-of-active-formatting-elements-up-to-the-last-marker
|
|
31
|
+
*/
|
|
27
32
|
clearToLastMarker(): void;
|
|
28
33
|
getElementEntryInScopeWithTagName(tagName: string): ElementEntry<T> | null;
|
|
29
34
|
getElementEntry(element: T['element']): ElementEntry<T> | undefined;
|
|
@@ -4,7 +4,7 @@ export var EntryType;
|
|
|
4
4
|
(function (EntryType) {
|
|
5
5
|
EntryType[EntryType["Marker"] = 0] = "Marker";
|
|
6
6
|
EntryType[EntryType["Element"] = 1] = "Element";
|
|
7
|
-
})(EntryType || (EntryType = {}));
|
|
7
|
+
})(EntryType = EntryType || (EntryType = {}));
|
|
8
8
|
const MARKER = { type: EntryType.Marker };
|
|
9
9
|
//List of formatting elements
|
|
10
10
|
export class FormattingElementList {
|
|
@@ -85,6 +85,11 @@ export class FormattingElementList {
|
|
|
85
85
|
this.entries.splice(entryIndex, 1);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Clears the list of formatting elements up to the last marker.
|
|
90
|
+
*
|
|
91
|
+
* @see https://html.spec.whatwg.org/multipage/parsing.html#clear-the-list-of-active-formatting-elements-up-to-the-last-marker
|
|
92
|
+
*/
|
|
88
93
|
clearToLastMarker() {
|
|
89
94
|
const markerIdx = this.entries.indexOf(MARKER);
|
|
90
95
|
if (markerIdx >= 0) {
|
package/dist/parser/index.js
CHANGED
|
@@ -1312,19 +1312,7 @@ function endTagInHead(p, token) {
|
|
|
1312
1312
|
break;
|
|
1313
1313
|
}
|
|
1314
1314
|
case $.TEMPLATE: {
|
|
1315
|
-
|
|
1316
|
-
p.openElements.generateImpliedEndTagsThoroughly();
|
|
1317
|
-
if (p.openElements.currentTagId !== $.TEMPLATE) {
|
|
1318
|
-
p._err(token, ERR.closingOfElementWithOpenChildElements);
|
|
1319
|
-
}
|
|
1320
|
-
p.openElements.popUntilTagNamePopped($.TEMPLATE);
|
|
1321
|
-
p.activeFormattingElements.clearToLastMarker();
|
|
1322
|
-
p.tmplInsertionModeStack.shift();
|
|
1323
|
-
p._resetInsertionMode();
|
|
1324
|
-
}
|
|
1325
|
-
else {
|
|
1326
|
-
p._err(token, ERR.endTagWithoutMatchingOpenElement);
|
|
1327
|
-
}
|
|
1315
|
+
templateEndTagInHead(p, token);
|
|
1328
1316
|
break;
|
|
1329
1317
|
}
|
|
1330
1318
|
default: {
|
|
@@ -1332,6 +1320,21 @@ function endTagInHead(p, token) {
|
|
|
1332
1320
|
}
|
|
1333
1321
|
}
|
|
1334
1322
|
}
|
|
1323
|
+
function templateEndTagInHead(p, token) {
|
|
1324
|
+
if (p.openElements.tmplCount > 0) {
|
|
1325
|
+
p.openElements.generateImpliedEndTagsThoroughly();
|
|
1326
|
+
if (p.openElements.currentTagId !== $.TEMPLATE) {
|
|
1327
|
+
p._err(token, ERR.closingOfElementWithOpenChildElements);
|
|
1328
|
+
}
|
|
1329
|
+
p.openElements.popUntilTagNamePopped($.TEMPLATE);
|
|
1330
|
+
p.activeFormattingElements.clearToLastMarker();
|
|
1331
|
+
p.tmplInsertionModeStack.shift();
|
|
1332
|
+
p._resetInsertionMode();
|
|
1333
|
+
}
|
|
1334
|
+
else {
|
|
1335
|
+
p._err(token, ERR.endTagWithoutMatchingOpenElement);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1335
1338
|
function tokenInHead(p, token) {
|
|
1336
1339
|
p.openElements.pop();
|
|
1337
1340
|
p.insertionMode = InsertionMode.AFTER_HEAD;
|
|
@@ -1440,7 +1443,7 @@ function endTagAfterHead(p, token) {
|
|
|
1440
1443
|
break;
|
|
1441
1444
|
}
|
|
1442
1445
|
case $.TEMPLATE: {
|
|
1443
|
-
|
|
1446
|
+
templateEndTagInHead(p, token);
|
|
1444
1447
|
break;
|
|
1445
1448
|
}
|
|
1446
1449
|
default: {
|
|
@@ -2100,6 +2103,7 @@ function endTagInBody(p, token) {
|
|
|
2100
2103
|
case $.MAIN:
|
|
2101
2104
|
case $.MENU:
|
|
2102
2105
|
case $.ASIDE:
|
|
2106
|
+
case $.BUTTON:
|
|
2103
2107
|
case $.CENTER:
|
|
2104
2108
|
case $.FIGURE:
|
|
2105
2109
|
case $.FOOTER:
|
|
@@ -2159,7 +2163,7 @@ function endTagInBody(p, token) {
|
|
|
2159
2163
|
break;
|
|
2160
2164
|
}
|
|
2161
2165
|
case $.TEMPLATE: {
|
|
2162
|
-
|
|
2166
|
+
templateEndTagInHead(p, token);
|
|
2163
2167
|
break;
|
|
2164
2168
|
}
|
|
2165
2169
|
default: {
|
|
@@ -2325,7 +2329,7 @@ function endTagInTable(p, token) {
|
|
|
2325
2329
|
break;
|
|
2326
2330
|
}
|
|
2327
2331
|
case $.TEMPLATE: {
|
|
2328
|
-
|
|
2332
|
+
templateEndTagInHead(p, token);
|
|
2329
2333
|
break;
|
|
2330
2334
|
}
|
|
2331
2335
|
case $.BODY:
|
|
@@ -2462,7 +2466,7 @@ function endTagInColumnGroup(p, token) {
|
|
|
2462
2466
|
break;
|
|
2463
2467
|
}
|
|
2464
2468
|
case $.TEMPLATE: {
|
|
2465
|
-
|
|
2469
|
+
templateEndTagInHead(p, token);
|
|
2466
2470
|
break;
|
|
2467
2471
|
}
|
|
2468
2472
|
case $.COL: {
|
|
@@ -2757,7 +2761,7 @@ function endTagInSelect(p, token) {
|
|
|
2757
2761
|
break;
|
|
2758
2762
|
}
|
|
2759
2763
|
case $.TEMPLATE: {
|
|
2760
|
-
|
|
2764
|
+
templateEndTagInHead(p, token);
|
|
2761
2765
|
break;
|
|
2762
2766
|
}
|
|
2763
2767
|
default:
|
|
@@ -2855,7 +2859,7 @@ function startTagInTemplate(p, token) {
|
|
|
2855
2859
|
}
|
|
2856
2860
|
function endTagInTemplate(p, token) {
|
|
2857
2861
|
if (token.tagID === $.TEMPLATE) {
|
|
2858
|
-
|
|
2862
|
+
templateEndTagInHead(p, token);
|
|
2859
2863
|
}
|
|
2860
2864
|
}
|
|
2861
2865
|
function eofInTemplate(p, token) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TAG_ID as $ } from '../common/html.js';
|
|
2
|
-
import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface';
|
|
2
|
+
import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface.js';
|
|
3
3
|
export interface StackHandler<T extends TreeAdapterTypeMap> {
|
|
4
4
|
onItemPush: (node: T['parentNode'], tid: number, isTop: boolean) => void;
|
|
5
5
|
onItemPop: (node: T['parentNode'], isTop: boolean) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface';
|
|
1
|
+
import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface.js';
|
|
2
2
|
import { type DefaultTreeAdapterMap } from '../tree-adapters/default.js';
|
|
3
3
|
export interface SerializerOptions<T extends TreeAdapterTypeMap> {
|
|
4
4
|
/**
|
|
@@ -78,10 +78,9 @@ declare const enum State {
|
|
|
78
78
|
AMBIGUOUS_AMPERSAND = 73,
|
|
79
79
|
NUMERIC_CHARACTER_REFERENCE = 74,
|
|
80
80
|
HEXADEMICAL_CHARACTER_REFERENCE_START = 75,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
NUMERIC_CHARACTER_REFERENCE_END = 79
|
|
81
|
+
HEXADEMICAL_CHARACTER_REFERENCE = 76,
|
|
82
|
+
DECIMAL_CHARACTER_REFERENCE = 77,
|
|
83
|
+
NUMERIC_CHARACTER_REFERENCE_END = 78
|
|
85
84
|
}
|
|
86
85
|
export declare const TokenizerMode: {
|
|
87
86
|
readonly DATA: State.DATA;
|
|
@@ -241,7 +240,6 @@ export declare class Tokenizer {
|
|
|
241
240
|
private _stateAmbiguousAmpersand;
|
|
242
241
|
private _stateNumericCharacterReference;
|
|
243
242
|
private _stateHexademicalCharacterReferenceStart;
|
|
244
|
-
private _stateDecimalCharacterReferenceStart;
|
|
245
243
|
private _stateHexademicalCharacterReference;
|
|
246
244
|
private _stateDecimalCharacterReference;
|
|
247
245
|
private _stateNumericCharacterReferenceEnd;
|
package/dist/tokenizer/index.js
CHANGED
|
@@ -113,10 +113,9 @@ var State;
|
|
|
113
113
|
State[State["AMBIGUOUS_AMPERSAND"] = 73] = "AMBIGUOUS_AMPERSAND";
|
|
114
114
|
State[State["NUMERIC_CHARACTER_REFERENCE"] = 74] = "NUMERIC_CHARACTER_REFERENCE";
|
|
115
115
|
State[State["HEXADEMICAL_CHARACTER_REFERENCE_START"] = 75] = "HEXADEMICAL_CHARACTER_REFERENCE_START";
|
|
116
|
-
State[State["
|
|
117
|
-
State[State["
|
|
118
|
-
State[State["
|
|
119
|
-
State[State["NUMERIC_CHARACTER_REFERENCE_END"] = 79] = "NUMERIC_CHARACTER_REFERENCE_END";
|
|
116
|
+
State[State["HEXADEMICAL_CHARACTER_REFERENCE"] = 76] = "HEXADEMICAL_CHARACTER_REFERENCE";
|
|
117
|
+
State[State["DECIMAL_CHARACTER_REFERENCE"] = 77] = "DECIMAL_CHARACTER_REFERENCE";
|
|
118
|
+
State[State["NUMERIC_CHARACTER_REFERENCE_END"] = 78] = "NUMERIC_CHARACTER_REFERENCE_END";
|
|
120
119
|
})(State || (State = {}));
|
|
121
120
|
//Tokenizer initial states for different modes
|
|
122
121
|
export const TokenizerMode = {
|
|
@@ -274,9 +273,9 @@ export class Tokenizer {
|
|
|
274
273
|
this.consumedAfterSnapshot -= count;
|
|
275
274
|
this.preprocessor.retreat(count);
|
|
276
275
|
}
|
|
277
|
-
_reconsumeInState(state) {
|
|
276
|
+
_reconsumeInState(state, cp) {
|
|
278
277
|
this.state = state;
|
|
279
|
-
this.
|
|
278
|
+
this._callState(cp);
|
|
280
279
|
}
|
|
281
280
|
_advanceBy(count) {
|
|
282
281
|
this.consumedAfterSnapshot += count;
|
|
@@ -472,13 +471,11 @@ export class Tokenizer {
|
|
|
472
471
|
this._createCharacterToken(type, ch);
|
|
473
472
|
}
|
|
474
473
|
_emitCodePoint(cp) {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
type = TokenType.NULL_CHARACTER;
|
|
481
|
-
}
|
|
474
|
+
const type = isWhitespace(cp)
|
|
475
|
+
? TokenType.WHITESPACE_CHARACTER
|
|
476
|
+
: cp === $.NULL
|
|
477
|
+
? TokenType.NULL_CHARACTER
|
|
478
|
+
: TokenType.CHARACTER;
|
|
482
479
|
this._appendCharToCurrentCharacterToken(type, String.fromCodePoint(cp));
|
|
483
480
|
}
|
|
484
481
|
//NOTE: used when we emit characters explicitly.
|
|
@@ -861,10 +858,6 @@ export class Tokenizer {
|
|
|
861
858
|
this._stateHexademicalCharacterReferenceStart(cp);
|
|
862
859
|
break;
|
|
863
860
|
}
|
|
864
|
-
case State.DECIMAL_CHARACTER_REFERENCE_START: {
|
|
865
|
-
this._stateDecimalCharacterReferenceStart(cp);
|
|
866
|
-
break;
|
|
867
|
-
}
|
|
868
861
|
case State.HEXADEMICAL_CHARACTER_REFERENCE: {
|
|
869
862
|
this._stateHexademicalCharacterReference(cp);
|
|
870
863
|
break;
|
|
@@ -874,7 +867,7 @@ export class Tokenizer {
|
|
|
874
867
|
break;
|
|
875
868
|
}
|
|
876
869
|
case State.NUMERIC_CHARACTER_REFERENCE_END: {
|
|
877
|
-
this._stateNumericCharacterReferenceEnd();
|
|
870
|
+
this._stateNumericCharacterReferenceEnd(cp);
|
|
878
871
|
break;
|
|
879
872
|
}
|
|
880
873
|
default: {
|
|
@@ -2772,7 +2765,7 @@ export class Tokenizer {
|
|
|
2772
2765
|
}
|
|
2773
2766
|
else {
|
|
2774
2767
|
this._flushCodePointConsumedAsCharacterReference($.AMPERSAND);
|
|
2775
|
-
this._reconsumeInState(this.returnState);
|
|
2768
|
+
this._reconsumeInState(this.returnState, cp);
|
|
2776
2769
|
}
|
|
2777
2770
|
}
|
|
2778
2771
|
// Named character reference state
|
|
@@ -2805,7 +2798,7 @@ export class Tokenizer {
|
|
|
2805
2798
|
if (cp === $.SEMICOLON) {
|
|
2806
2799
|
this._err(ERR.unknownNamedCharacterReference);
|
|
2807
2800
|
}
|
|
2808
|
-
this._reconsumeInState(this.returnState);
|
|
2801
|
+
this._reconsumeInState(this.returnState, cp);
|
|
2809
2802
|
}
|
|
2810
2803
|
}
|
|
2811
2804
|
// Numeric character reference state
|
|
@@ -2815,9 +2808,16 @@ export class Tokenizer {
|
|
|
2815
2808
|
if (cp === $.LATIN_SMALL_X || cp === $.LATIN_CAPITAL_X) {
|
|
2816
2809
|
this.state = State.HEXADEMICAL_CHARACTER_REFERENCE_START;
|
|
2817
2810
|
}
|
|
2811
|
+
// Inlined decimal character reference start state
|
|
2812
|
+
else if (isAsciiDigit(cp)) {
|
|
2813
|
+
this.state = State.DECIMAL_CHARACTER_REFERENCE;
|
|
2814
|
+
this._stateDecimalCharacterReference(cp);
|
|
2815
|
+
}
|
|
2818
2816
|
else {
|
|
2819
|
-
this.
|
|
2820
|
-
this.
|
|
2817
|
+
this._err(ERR.absenceOfDigitsInNumericCharacterReference);
|
|
2818
|
+
this._flushCodePointConsumedAsCharacterReference($.AMPERSAND);
|
|
2819
|
+
this._flushCodePointConsumedAsCharacterReference($.NUMBER_SIGN);
|
|
2820
|
+
this._reconsumeInState(this.returnState, cp);
|
|
2821
2821
|
}
|
|
2822
2822
|
}
|
|
2823
2823
|
// Hexademical character reference start state
|
|
@@ -2835,20 +2835,6 @@ export class Tokenizer {
|
|
|
2835
2835
|
this.state = this.returnState;
|
|
2836
2836
|
}
|
|
2837
2837
|
}
|
|
2838
|
-
// Decimal character reference start state
|
|
2839
|
-
//------------------------------------------------------------------
|
|
2840
|
-
_stateDecimalCharacterReferenceStart(cp) {
|
|
2841
|
-
if (isAsciiDigit(cp)) {
|
|
2842
|
-
this.state = State.DECIMAL_CHARACTER_REFERENCE;
|
|
2843
|
-
this._stateDecimalCharacterReference(cp);
|
|
2844
|
-
}
|
|
2845
|
-
else {
|
|
2846
|
-
this._err(ERR.absenceOfDigitsInNumericCharacterReference);
|
|
2847
|
-
this._flushCodePointConsumedAsCharacterReference($.AMPERSAND);
|
|
2848
|
-
this._flushCodePointConsumedAsCharacterReference($.NUMBER_SIGN);
|
|
2849
|
-
this._reconsumeInState(this.returnState);
|
|
2850
|
-
}
|
|
2851
|
-
}
|
|
2852
2838
|
// Hexademical character reference state
|
|
2853
2839
|
//------------------------------------------------------------------
|
|
2854
2840
|
_stateHexademicalCharacterReference(cp) {
|
|
@@ -2867,7 +2853,7 @@ export class Tokenizer {
|
|
|
2867
2853
|
else {
|
|
2868
2854
|
this._err(ERR.missingSemicolonAfterCharacterReference);
|
|
2869
2855
|
this.state = State.NUMERIC_CHARACTER_REFERENCE_END;
|
|
2870
|
-
this._stateNumericCharacterReferenceEnd();
|
|
2856
|
+
this._stateNumericCharacterReferenceEnd(cp);
|
|
2871
2857
|
}
|
|
2872
2858
|
}
|
|
2873
2859
|
// Decimal character reference state
|
|
@@ -2882,12 +2868,12 @@ export class Tokenizer {
|
|
|
2882
2868
|
else {
|
|
2883
2869
|
this._err(ERR.missingSemicolonAfterCharacterReference);
|
|
2884
2870
|
this.state = State.NUMERIC_CHARACTER_REFERENCE_END;
|
|
2885
|
-
this._stateNumericCharacterReferenceEnd();
|
|
2871
|
+
this._stateNumericCharacterReferenceEnd(cp);
|
|
2886
2872
|
}
|
|
2887
2873
|
}
|
|
2888
2874
|
// Numeric character reference end state
|
|
2889
2875
|
//------------------------------------------------------------------
|
|
2890
|
-
_stateNumericCharacterReferenceEnd() {
|
|
2876
|
+
_stateNumericCharacterReferenceEnd(cp) {
|
|
2891
2877
|
if (this.charRefCode === $.NULL) {
|
|
2892
2878
|
this._err(ERR.nullCharacterReference);
|
|
2893
2879
|
this.charRefCode = $.REPLACEMENT_CHARACTER;
|
|
@@ -2911,7 +2897,7 @@ export class Tokenizer {
|
|
|
2911
2897
|
}
|
|
2912
2898
|
}
|
|
2913
2899
|
this._flushCodePointConsumedAsCharacterReference(this.charRefCode);
|
|
2914
|
-
this._reconsumeInState(this.returnState);
|
|
2900
|
+
this._reconsumeInState(this.returnState, cp);
|
|
2915
2901
|
}
|
|
2916
2902
|
}
|
|
2917
2903
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { DOCUMENT_MODE, type NS } from '../common/html.js';
|
|
2
2
|
import type { Attribute, Location, ElementLocation } from '../common/token.js';
|
|
3
3
|
import type { TreeAdapter, TreeAdapterTypeMap } from './interface.js';
|
|
4
|
-
export declare enum NodeType {
|
|
5
|
-
Document = "#document",
|
|
6
|
-
DocumentFragment = "#document-fragment",
|
|
7
|
-
Comment = "#comment",
|
|
8
|
-
Text = "#text",
|
|
9
|
-
DocumentType = "#documentType"
|
|
10
|
-
}
|
|
11
4
|
export interface Document {
|
|
12
5
|
/** The name of the node. */
|
|
13
|
-
nodeName:
|
|
6
|
+
nodeName: '#document';
|
|
14
7
|
/**
|
|
15
8
|
* Document mode.
|
|
16
9
|
*
|
|
@@ -23,7 +16,7 @@ export interface Document {
|
|
|
23
16
|
}
|
|
24
17
|
export interface DocumentFragment {
|
|
25
18
|
/** The name of the node. */
|
|
26
|
-
nodeName:
|
|
19
|
+
nodeName: '#document-fragment';
|
|
27
20
|
/** The node's children. */
|
|
28
21
|
childNodes: ChildNode[];
|
|
29
22
|
/** Comment source code location info. Available if location info is enabled. */
|
|
@@ -47,7 +40,7 @@ export interface Element {
|
|
|
47
40
|
}
|
|
48
41
|
export interface CommentNode {
|
|
49
42
|
/** The name of the node. */
|
|
50
|
-
nodeName:
|
|
43
|
+
nodeName: '#comment';
|
|
51
44
|
/** Parent node. */
|
|
52
45
|
parentNode: ParentNode | null;
|
|
53
46
|
/** Comment text. */
|
|
@@ -56,7 +49,7 @@ export interface CommentNode {
|
|
|
56
49
|
sourceCodeLocation?: Location | null;
|
|
57
50
|
}
|
|
58
51
|
export interface TextNode {
|
|
59
|
-
nodeName:
|
|
52
|
+
nodeName: '#text';
|
|
60
53
|
/** Parent node. */
|
|
61
54
|
parentNode: ParentNode | null;
|
|
62
55
|
/** Text content. */
|
|
@@ -72,7 +65,7 @@ export interface Template extends Element {
|
|
|
72
65
|
}
|
|
73
66
|
export interface DocumentType {
|
|
74
67
|
/** The name of the node. */
|
|
75
|
-
nodeName:
|
|
68
|
+
nodeName: '#documentType';
|
|
76
69
|
/** Parent node. */
|
|
77
70
|
parentNode: ParentNode | null;
|
|
78
71
|
/** Document type name. */
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { DOCUMENT_MODE } from '../common/html.js';
|
|
2
|
-
export var NodeType;
|
|
3
|
-
(function (NodeType) {
|
|
4
|
-
NodeType["Document"] = "#document";
|
|
5
|
-
NodeType["DocumentFragment"] = "#document-fragment";
|
|
6
|
-
NodeType["Comment"] = "#comment";
|
|
7
|
-
NodeType["Text"] = "#text";
|
|
8
|
-
NodeType["DocumentType"] = "#documentType";
|
|
9
|
-
})(NodeType || (NodeType = {}));
|
|
10
2
|
function createTextNode(value) {
|
|
11
3
|
return {
|
|
12
|
-
nodeName:
|
|
4
|
+
nodeName: '#text',
|
|
13
5
|
value,
|
|
14
6
|
parentNode: null,
|
|
15
7
|
};
|
|
@@ -18,14 +10,14 @@ export const defaultTreeAdapter = {
|
|
|
18
10
|
//Node construction
|
|
19
11
|
createDocument() {
|
|
20
12
|
return {
|
|
21
|
-
nodeName:
|
|
13
|
+
nodeName: '#document',
|
|
22
14
|
mode: DOCUMENT_MODE.NO_QUIRKS,
|
|
23
15
|
childNodes: [],
|
|
24
16
|
};
|
|
25
17
|
},
|
|
26
18
|
createDocumentFragment() {
|
|
27
19
|
return {
|
|
28
|
-
nodeName:
|
|
20
|
+
nodeName: '#document-fragment',
|
|
29
21
|
childNodes: [],
|
|
30
22
|
};
|
|
31
23
|
},
|
|
@@ -41,7 +33,7 @@ export const defaultTreeAdapter = {
|
|
|
41
33
|
},
|
|
42
34
|
createCommentNode(data) {
|
|
43
35
|
return {
|
|
44
|
-
nodeName:
|
|
36
|
+
nodeName: '#comment',
|
|
45
37
|
data,
|
|
46
38
|
parentNode: null,
|
|
47
39
|
};
|
|
@@ -63,7 +55,7 @@ export const defaultTreeAdapter = {
|
|
|
63
55
|
return templateElement.content;
|
|
64
56
|
},
|
|
65
57
|
setDocumentType(document, name, publicId, systemId) {
|
|
66
|
-
const doctypeNode = document.childNodes.find((node) => node.nodeName ===
|
|
58
|
+
const doctypeNode = document.childNodes.find((node) => node.nodeName === '#documentType');
|
|
67
59
|
if (doctypeNode) {
|
|
68
60
|
doctypeNode.name = name;
|
|
69
61
|
doctypeNode.publicId = publicId;
|
|
@@ -71,7 +63,7 @@ export const defaultTreeAdapter = {
|
|
|
71
63
|
}
|
|
72
64
|
else {
|
|
73
65
|
const node = {
|
|
74
|
-
nodeName:
|
|
66
|
+
nodeName: '#documentType',
|
|
75
67
|
name,
|
|
76
68
|
publicId,
|
|
77
69
|
systemId,
|
|
@@ -163,7 +155,7 @@ export const defaultTreeAdapter = {
|
|
|
163
155
|
return node.nodeName === '#comment';
|
|
164
156
|
},
|
|
165
157
|
isDocumentTypeNode(node) {
|
|
166
|
-
return node.nodeName ===
|
|
158
|
+
return node.nodeName === '#documentType';
|
|
167
159
|
},
|
|
168
160
|
isElementNode(node) {
|
|
169
161
|
return Object.prototype.hasOwnProperty.call(node, 'tagName');
|
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.1.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://github.com/inikulin/parse5",
|
|
9
9
|
"funding": "https://github.com/inikulin/parse5?sponsor=1",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"entities": "^4.
|
|
11
|
+
"entities": "^4.4.0"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"html",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"url": "git://github.com/inikulin/parse5.git"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
|
-
"dist",
|
|
47
|
-
"
|
|
46
|
+
"dist/**/*.js",
|
|
47
|
+
"dist/**/*.d.ts"
|
|
48
48
|
]
|
|
49
49
|
}
|
package/dist/cjs/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|