UNPKG

2.63 kBTypeScriptView Raw
1import { ChildNode, Element, DataNode, Document, ParentNode } from "./node.js";
2export * from "./node.js";
3export interface DomHandlerOptions {
4 /**
5 * Add a `startIndex` property to nodes.
6 * When the parser is used in a non-streaming fashion, `startIndex` is an integer
7 * indicating the position of the start of the node in the document.
8 *
9 * @default false
10 */
11 withStartIndices?: boolean;
12 /**
13 * Add an `endIndex` property to nodes.
14 * When the parser is used in a non-streaming fashion, `endIndex` is an integer
15 * indicating the position of the end of the node in the document.
16 *
17 * @default false
18 */
19 withEndIndices?: boolean;
20 /**
21 * Treat the markup as XML.
22 *
23 * @default false
24 */
25 xmlMode?: boolean;
26}
27interface ParserInterface {
28 startIndex: number | null;
29 endIndex: number | null;
30}
31declare type Callback = (error: Error | null, dom: ChildNode[]) => void;
32declare type ElementCallback = (element: Element) => void;
33export declare class DomHandler {
34 /** The elements of the DOM */
35 dom: ChildNode[];
36 /** The root element for the DOM */
37 root: Document;
38 /** Called once parsing has completed. */
39 private readonly callback;
40 /** Settings for the handler. */
41 private readonly options;
42 /** Callback whenever a tag is closed. */
43 private readonly elementCB;
44 /** Indicated whether parsing has been completed. */
45 private done;
46 /** Stack of open tags. */
47 protected tagStack: ParentNode[];
48 /** A data node that is still being written to. */
49 protected lastNode: DataNode | null;
50 /** Reference to the parser instance. Used for location information. */
51 private parser;
52 /**
53 * @param callback Called once parsing has completed.
54 * @param options Settings for the handler.
55 * @param elementCB Callback whenever a tag is closed.
56 */
57 constructor(callback?: Callback | null, options?: DomHandlerOptions | null, elementCB?: ElementCallback);
58 onparserinit(parser: ParserInterface): void;
59 onreset(): void;
60 onend(): void;
61 onerror(error: Error): void;
62 onclosetag(): void;
63 onopentag(name: string, attribs: {
64 [key: string]: string;
65 }): void;
66 ontext(data: string): void;
67 oncomment(data: string): void;
68 oncommentend(): void;
69 oncdatastart(): void;
70 oncdataend(): void;
71 onprocessinginstruction(name: string, data: string): void;
72 protected handleCallback(error: Error | null): void;
73 protected addNode(node: ChildNode): void;
74}
75export default DomHandler;
76//# sourceMappingURL=index.d.ts.map
\No newline at end of file