parse5 8.1.0 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/dist/common/foreign-content.d.ts +1 -1
- package/dist/parser/formatting-element-list.d.ts +38 -10
- package/dist/parser/formatting-element-list.js +153 -70
- package/dist/parser/index.d.ts +6 -2
- package/dist/parser/index.js +169 -135
- package/dist/parser/open-element-stack.d.ts +85 -8
- package/dist/parser/open-element-stack.js +500 -150
- package/dist/serializer/index.js +48 -34
- package/dist/tokenizer/index.d.ts +3 -0
- package/dist/tokenizer/index.js +59 -5
- package/dist/tokenizer/preprocessor.d.ts +5 -1
- package/dist/tokenizer/preprocessor.js +8 -4
- package/dist/tree-adapters/default.js +50 -6
- package/package.json +1 -1
|
@@ -1,46 +1,123 @@
|
|
|
1
|
-
import { TAG_ID as
|
|
1
|
+
import { TAG_ID as $, NS } from '../common/html.js';
|
|
2
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;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* The stack of open elements. Each element has a slot in `items` and `tagIDs`. Once the stack is `INDEX_DEPTH` deep, it
|
|
9
|
+
* indexes its elements so that the searches the parser repeats per token take constant time: it chains the elements
|
|
10
|
+
* with each key, so that the topmost one is found without a scan, and counts per slot the special elements and scope
|
|
11
|
+
* boundaries at or below it, which tell whether one lies between two slots. Removing an element from the middle then
|
|
12
|
+
* leaves its slot free instead of moving the elements above it; `slotBelow` and `slotAbove` step over free slots, and
|
|
13
|
+
* `depth` counts the open elements.
|
|
14
|
+
*/
|
|
7
15
|
export declare class OpenElementStack<T extends TreeAdapterTypeMap> {
|
|
8
16
|
private treeAdapter;
|
|
9
17
|
private handler;
|
|
10
18
|
items: T['parentNode'][];
|
|
11
19
|
tagIDs: $[];
|
|
12
20
|
current: T['parentNode'] | undefined;
|
|
21
|
+
/** The slot of the current element. */
|
|
13
22
|
stackTop: number;
|
|
23
|
+
/** The number of open elements. */
|
|
24
|
+
depth: number;
|
|
14
25
|
tmplCount: number;
|
|
15
26
|
currentTagId: number | undefined;
|
|
27
|
+
private indexed;
|
|
28
|
+
/** The slot of the open element below, and above, each open element's slot; -1 for none. */
|
|
29
|
+
private below;
|
|
30
|
+
private above;
|
|
31
|
+
private keys;
|
|
32
|
+
/** The slot of the next lower, and higher, open element with the same key; -1 for none. */
|
|
33
|
+
private keyPrev;
|
|
34
|
+
private keyNext;
|
|
35
|
+
/** The slot of the topmost open element with each key, -1 for none. */
|
|
36
|
+
private keyTops;
|
|
37
|
+
private nameKeys;
|
|
38
|
+
/** Per slot, the open special elements, list item boundaries and scope boundaries at or below it. */
|
|
39
|
+
private specials;
|
|
40
|
+
private listItemBoundaries;
|
|
41
|
+
private scopeBoundaries;
|
|
42
|
+
/** Per slot, the slot of the topmost open HTML element at or below it, or -1. */
|
|
43
|
+
private htmlSlots;
|
|
44
|
+
private formattingSlots;
|
|
16
45
|
get currentTmplContentOrNode(): T['parentNode'];
|
|
17
46
|
constructor(document: T['document'], treeAdapter: TreeAdapter<T>, handler: StackHandler<T>);
|
|
18
|
-
|
|
47
|
+
/** The slot of an open element, or -1. */
|
|
48
|
+
_indexOf(element: T['element']): number;
|
|
49
|
+
/** The slot of the open element below the one at `idx`, or -1. */
|
|
50
|
+
slotBelow(idx: number): number;
|
|
51
|
+
/** The slot of the open element above the one at `idx`, or -1. */
|
|
52
|
+
slotAbove(idx: number): number;
|
|
19
53
|
private _isInTemplate;
|
|
20
54
|
private _updateCurrentElement;
|
|
55
|
+
private _nameKey;
|
|
56
|
+
/** Indexes the open elements once the stack is `INDEX_DEPTH` deep. */
|
|
57
|
+
private _indexAll;
|
|
58
|
+
/** Indexes the element at `slot`, above the open element at `belowIdx`. */
|
|
59
|
+
private _index;
|
|
60
|
+
/** Puts the indexed element at `slot` above the one at `belowIdx`, and counts the elements of each class. */
|
|
61
|
+
private _link;
|
|
62
|
+
/** Takes the element at `slot` out of the index, except for the links between slots. */
|
|
63
|
+
private _unindex;
|
|
64
|
+
/** Moves the indexed element at `from` down to the free slot `to`, keeping its key chain in order. */
|
|
65
|
+
private _move;
|
|
66
|
+
/** The slot of the topmost open HTML element with this tag, or -1. */
|
|
67
|
+
indexOfTopmost(tagID: $): number;
|
|
68
|
+
/** The slot of the topmost open HTML element with any of these tags, or -1. */
|
|
69
|
+
indexOfTopmostOf(tagIDs: readonly $[]): number;
|
|
70
|
+
/** The slot of the topmost open element in this namespace with this tag name, or -1. */
|
|
71
|
+
indexOfTopmostByName(ns: NS, tagName: string): number;
|
|
72
|
+
/** The slot of the topmost open HTML element, or -1. */
|
|
73
|
+
indexOfTopmostHtmlElement(): number;
|
|
74
|
+
/** Whether an element of the classes is open above the slot `idx`, on a stack that is not indexed. */
|
|
75
|
+
private _hasAbove;
|
|
76
|
+
/** Whether a special element is open above the slot `idx`. */
|
|
77
|
+
hasSpecialElementAbove(idx: number): boolean;
|
|
78
|
+
/** Whether a special element other than HTML `address`, `div` and `p` is open above the slot `idx`. */
|
|
79
|
+
hasListItemBoundaryAbove(idx: number): boolean;
|
|
21
80
|
push(element: T['element'], tagID: $): void;
|
|
81
|
+
/** Pops the current element without calling the handler. */
|
|
82
|
+
private _popCurrent;
|
|
22
83
|
pop(): void;
|
|
23
84
|
replace(oldElement: T['element'], newElement: T['element']): void;
|
|
24
|
-
|
|
85
|
+
/**
|
|
86
|
+
* The adoption agency's last stack step: removes the formatting element at `formattingIdx` and opens `element`
|
|
87
|
+
* directly above the furthest block at `furthestBlockIdx`. On an indexed stack, only formatting elements the agency
|
|
88
|
+
* kept are still open between them; the furthest block, with those directly below it, moves down by one slot, and
|
|
89
|
+
* `element` takes the furthest block's slot. No open element above the furthest block moves, and as all these
|
|
90
|
+
* elements are HTML elements and only the furthest block is special, the counts above it stay the same.
|
|
91
|
+
*/
|
|
92
|
+
replaceFormattingElement(formattingIdx: number, furthestBlockIdx: number, element: T['element'], tagID: $): void;
|
|
25
93
|
popUntilTagNamePopped(tagName: $): void;
|
|
26
94
|
shortenToLength(idx: number): void;
|
|
27
95
|
popUntilElementPopped(element: T['element']): void;
|
|
28
|
-
private popUntilPopped;
|
|
29
96
|
popUntilNumberedHeaderPopped(): void;
|
|
30
97
|
popUntilTableCellPopped(): void;
|
|
31
98
|
popAllUpToHtmlElement(): void;
|
|
32
|
-
private _indexOfTagNames;
|
|
33
|
-
private clearBackTo;
|
|
34
99
|
clearBackToTableContext(): void;
|
|
35
100
|
clearBackToTableBodyContext(): void;
|
|
36
101
|
clearBackToTableRowContext(): void;
|
|
37
102
|
remove(element: T['element']): void;
|
|
103
|
+
/** Removes the open element at the slot `idx`; on an indexed stack, the elements above it keep their slots. */
|
|
104
|
+
removeAt(idx: number): void;
|
|
38
105
|
tryPeekProperlyNestedBodyElement(): T['element'] | null;
|
|
39
106
|
contains(element: T['element']): boolean;
|
|
40
107
|
getCommonAncestor(element: T['element']): T['element'] | null;
|
|
41
108
|
isRootHtmlElementCurrent(): boolean;
|
|
42
|
-
|
|
43
|
-
|
|
109
|
+
/**
|
|
110
|
+
* On an indexed stack: whether no element of the `scope` class is open above the slot `target`. A target that is not
|
|
111
|
+
* open is in scope only on a stack without such an element, as a scan from the top would end there.
|
|
112
|
+
*/
|
|
113
|
+
private _isInScope;
|
|
114
|
+
/**
|
|
115
|
+
* On a stack that is not indexed: whether an HTML element with the tag, or one of the tags, and if passed the element
|
|
116
|
+
* itself, is open above every element of the `scope` class; true if neither is open.
|
|
117
|
+
*/
|
|
118
|
+
private _scanScope;
|
|
119
|
+
/** If `element` is passed, only that element (which has to be a `tagName` element) is looked for. */
|
|
120
|
+
hasInScope(tagName: $, element?: T['element'] | null): boolean;
|
|
44
121
|
hasInListItemScope(tagName: $): boolean;
|
|
45
122
|
hasInButtonScope(tagName: $): boolean;
|
|
46
123
|
hasNumberedHeaderInScope(): boolean;
|