1 | import Tokenizer, { type Callbacks, QuoteType } from "./Tokenizer.js";
|
2 | export interface ParserOptions {
|
3 | |
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | xmlMode?: boolean;
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 | decodeEntities?: boolean;
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 | lowerCaseTags?: boolean;
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 | lowerCaseAttributeNames?: boolean;
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | recognizeCDATA?: boolean;
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | recognizeSelfClosing?: boolean;
|
44 | |
45 |
|
46 |
|
47 | Tokenizer?: typeof Tokenizer;
|
48 | }
|
49 | export interface Handler {
|
50 | onparserinit(parser: Parser): void;
|
51 | |
52 |
|
53 |
|
54 | onreset(): void;
|
55 | |
56 |
|
57 |
|
58 | onend(): void;
|
59 | onerror(error: Error): void;
|
60 | onclosetag(name: string, isImplied: boolean): void;
|
61 | onopentagname(name: string): void;
|
62 | |
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | onattribute(name: string, value: string, quote?: string | undefined | null): void;
|
69 | onopentag(name: string, attribs: {
|
70 | [s: string]: string;
|
71 | }, isImplied: boolean): void;
|
72 | ontext(data: string): void;
|
73 | oncomment(data: string): void;
|
74 | oncdatastart(): void;
|
75 | oncdataend(): void;
|
76 | oncommentend(): void;
|
77 | onprocessinginstruction(name: string, data: string): void;
|
78 | }
|
79 | export declare class Parser implements Callbacks {
|
80 | private readonly options;
|
81 |
|
82 | startIndex: number;
|
83 |
|
84 | endIndex: number;
|
85 | |
86 |
|
87 |
|
88 |
|
89 | private openTagStart;
|
90 | private tagname;
|
91 | private attribname;
|
92 | private attribvalue;
|
93 | private attribs;
|
94 | private readonly stack;
|
95 |
|
96 | private readonly foreignContext;
|
97 | private readonly cbs;
|
98 | private readonly lowerCaseTagNames;
|
99 | private readonly lowerCaseAttributeNames;
|
100 | private readonly recognizeSelfClosing;
|
101 |
|
102 | private readonly htmlMode;
|
103 | private readonly tokenizer;
|
104 | private readonly buffers;
|
105 | private bufferOffset;
|
106 |
|
107 | private writeIndex;
|
108 |
|
109 | private ended;
|
110 | constructor(cbs?: Partial<Handler> | null, options?: ParserOptions);
|
111 | /** @internal */
|
112 | ontext(start: number, endIndex: number): void;
|
113 | /** @internal */
|
114 | ontextentity(cp: number, endIndex: number): void;
|
115 | /**
|
116 | * Checks if the current tag is a void element. Override this if you want
|
117 | * to specify your own additional void elements.
|
118 | */
|
119 | protected isVoidElement(name: string): boolean;
|
120 | /** @internal */
|
121 | onopentagname(start: number, endIndex: number): void;
|
122 | private emitOpenTag;
|
123 | private endOpenTag;
|
124 | /** @internal */
|
125 | onopentagend(endIndex: number): void;
|
126 | /** @internal */
|
127 | onclosetag(start: number, endIndex: number): void;
|
128 | /** @internal */
|
129 | onselfclosingtag(endIndex: number): void;
|
130 | private closeCurrentTag;
|
131 | /** @internal */
|
132 | onattribname(start: number, endIndex: number): void;
|
133 | /** @internal */
|
134 | onattribdata(start: number, endIndex: number): void;
|
135 | /** @internal */
|
136 | onattribentity(cp: number): void;
|
137 | /** @internal */
|
138 | onattribend(quote: QuoteType, endIndex: number): void;
|
139 | private getInstructionName;
|
140 | /** @internal */
|
141 | ondeclaration(start: number, endIndex: number): void;
|
142 | /** @internal */
|
143 | onprocessinginstruction(start: number, endIndex: number): void;
|
144 | /** @internal */
|
145 | oncomment(start: number, endIndex: number, offset: number): void;
|
146 | /** @internal */
|
147 | oncdata(start: number, endIndex: number, offset: number): void;
|
148 | /** @internal */
|
149 | onend(): void;
|
150 | /**
|
151 | * Resets the parser to a blank state, ready to parse a new HTML document
|
152 | */
|
153 | reset(): void;
|
154 | /**
|
155 | * Resets the parser, then parses a complete document and
|
156 | * pushes it to the handler.
|
157 | *
|
158 | * @param data Document to parse.
|
159 | */
|
160 | parseComplete(data: string): void;
|
161 | private getSlice;
|
162 | private shiftBuffer;
|
163 | /**
|
164 | * Parses a chunk of data and calls the corresponding callbacks.
|
165 | *
|
166 | * @param chunk Chunk to parse.
|
167 | */
|
168 | write(chunk: string): void;
|
169 | /**
|
170 | * Parses the end of the buffer and clears the stack, calls onend.
|
171 | *
|
172 | * @param chunk Optional final chunk to parse.
|
173 | */
|
174 | end(chunk?: string): void;
|
175 | /**
|
176 | * Pauses parsing. The parser won't emit events until `resume` is called.
|
177 | */
|
178 | pause(): void;
|
179 | /**
|
180 | * Resumes parsing after `pause` was called.
|
181 | */
|
182 | resume(): void;
|
183 | /**
|
184 | * Alias of `write`, for backwards compatibility.
|
185 | *
|
186 | * @param chunk Chunk to parse.
|
187 | * @deprecated
|
188 | */
|
189 | parseChunk(chunk: string): void;
|
190 | /**
|
191 | * Alias of `end`, for backwards compatibility.
|
192 | *
|
193 | * @param chunk Optional final chunk to parse.
|
194 | * @deprecated
|
195 | */
|
196 | done(chunk?: string): void;
|
197 | }
|
198 | //# sourceMappingURL=Parser.d.ts.map |
\ | No newline at end of file |