1 | import { Node, Element, DataNode, NodeWithChildren, Document } from "./node";
|
---|
2 | export * from "./node";
|
---|
3 | export 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 | * Replace all whitespace with single spaces.
|
---|
22 | *
|
---|
23 | * **Note:** Enabling this might break your markup.
|
---|
24 | *
|
---|
25 | * @default false
|
---|
26 | * @deprecated
|
---|
27 | */
|
---|
28 | normalizeWhitespace?: boolean;
|
---|
29 | /**
|
---|
30 | * Treat the markup as XML.
|
---|
31 | *
|
---|
32 | * @default false
|
---|
33 | */
|
---|
34 | xmlMode?: boolean;
|
---|
35 | }
|
---|
36 | interface ParserInterface {
|
---|
37 | startIndex: number | null;
|
---|
38 | endIndex: number | null;
|
---|
39 | }
|
---|
40 | declare type Callback = (error: Error | null, dom: Node[]) => void;
|
---|
41 | declare type ElementCallback = (element: Element) => void;
|
---|
42 | export declare class DomHandler {
|
---|
43 | /** The elements of the DOM */
|
---|
44 | dom: Node[];
|
---|
45 | /** The root element for the DOM */
|
---|
46 | root: Document;
|
---|
47 | /** Called once parsing has completed. */
|
---|
48 | private readonly callback;
|
---|
49 | /** Settings for the handler. */
|
---|
50 | private readonly options;
|
---|
51 | /** Callback whenever a tag is closed. */
|
---|
52 | private readonly elementCB;
|
---|
53 | /** Indicated whether parsing has been completed. */
|
---|
54 | private done;
|
---|
55 | /** Stack of open tags. */
|
---|
56 | protected tagStack: NodeWithChildren[];
|
---|
57 | /** A data node that is still being written to. */
|
---|
58 | protected lastNode: DataNode | null;
|
---|
59 | /** Reference to the parser instance. Used for location information. */
|
---|
60 | private parser;
|
---|
61 | /**
|
---|
62 | * @param callback Called once parsing has completed.
|
---|
63 | * @param options Settings for the handler.
|
---|
64 | * @param elementCB Callback whenever a tag is closed.
|
---|
65 | */
|
---|
66 | constructor(callback?: Callback | null, options?: DomHandlerOptions | null, elementCB?: ElementCallback);
|
---|
67 | onparserinit(parser: ParserInterface): void;
|
---|
68 | onreset(): void;
|
---|
69 | onend(): void;
|
---|
70 | onerror(error: Error): void;
|
---|
71 | onclosetag(): void;
|
---|
72 | onopentag(name: string, attribs: {
|
---|
73 | [key: string]: string;
|
---|
74 | }): void;
|
---|
75 | ontext(data: string): void;
|
---|
76 | oncomment(data: string): void;
|
---|
77 | oncommentend(): void;
|
---|
78 | oncdatastart(): void;
|
---|
79 | oncdataend(): void;
|
---|
80 | onprocessinginstruction(name: string, data: string): void;
|
---|
81 | protected handleCallback(error: Error | null): void;
|
---|
82 | protected addNode(node: Node): void;
|
---|
83 | }
|
---|
84 | export default DomHandler;
|
---|
85 | //# sourceMappingURL=index.d.ts.map |
---|