1 | export interface ContentTypeOptions {
|
2 | html?: boolean;
|
3 | }
|
4 |
|
5 | export class Element {
|
6 | before(content: string, options?: ContentTypeOptions): this;
|
7 | after(content: string, options?: ContentTypeOptions): this;
|
8 | replace(content: string, options?: ContentTypeOptions): this;
|
9 | remove(): this;
|
10 | getAttribute(name: string): string | null;
|
11 | hasAttribute(name: string): boolean;
|
12 | setAttribute(name: string, value: string): this;
|
13 | removeAttribute(name: string): this;
|
14 | prepend(content: string, options?: ContentTypeOptions): this;
|
15 | append(content: string, options?: ContentTypeOptions): this;
|
16 | setInnerContent(content: string, options?: ContentTypeOptions): this;
|
17 | removeAndKeepContent(): this;
|
18 | readonly attributes: IterableIterator<[string, string]>;
|
19 | readonly namespaceURI: string;
|
20 | readonly removed: boolean;
|
21 | tagName: string;
|
22 | onEndTag(handler: (this: this, endTag: EndTag) => void | Promise<void>): void;
|
23 | }
|
24 |
|
25 | export class EndTag {
|
26 | before(content: string, options?: ContentTypeOptions): this;
|
27 | after(content: string, options?: ContentTypeOptions): this;
|
28 | remove(): this;
|
29 | name: string;
|
30 | }
|
31 |
|
32 | export class Comment {
|
33 | before(content: string, options?: ContentTypeOptions): this;
|
34 | after(content: string, options?: ContentTypeOptions): this;
|
35 | replace(content: string, options?: ContentTypeOptions): this;
|
36 | remove(): this;
|
37 | readonly removed: boolean;
|
38 | text: string;
|
39 | }
|
40 |
|
41 | export class TextChunk {
|
42 | before(content: string, options?: ContentTypeOptions): this;
|
43 | after(content: string, options?: ContentTypeOptions): this;
|
44 | replace(content: string, options?: ContentTypeOptions): this;
|
45 | remove(): this;
|
46 | readonly lastInTextNode: boolean;
|
47 | readonly removed: boolean;
|
48 | readonly text: string;
|
49 | }
|
50 |
|
51 | export class Doctype {
|
52 | readonly name: string | null;
|
53 | readonly publicId: string | null;
|
54 | readonly systemId: string | null;
|
55 | }
|
56 |
|
57 | export class DocumentEnd {
|
58 | append(content: string, options?: ContentTypeOptions): this;
|
59 | }
|
60 |
|
61 | export interface ElementHandlers {
|
62 | element?(element: Element): void | Promise<void>;
|
63 | comments?(comment: Comment): void | Promise<void>;
|
64 | text?(text: TextChunk): void | Promise<void>;
|
65 | }
|
66 |
|
67 | export interface DocumentHandlers {
|
68 | doctype?(doctype: Doctype): void | Promise<void>;
|
69 | comments?(comment: Comment): void | Promise<void>;
|
70 | text?(text: TextChunk): void | Promise<void>;
|
71 | end?(end: DocumentEnd): void | Promise<void>;
|
72 | }
|
73 |
|
74 | export interface HTMLRewriterOptions {
|
75 | enableEsiTags?: boolean;
|
76 | }
|
77 |
|
78 | export class HTMLRewriter {
|
79 | constructor(
|
80 | outputSink: (chunk: Uint8Array) => void,
|
81 | options?: HTMLRewriterOptions
|
82 | );
|
83 | on(selector: string, handlers: ElementHandlers): this;
|
84 | onDocument(handlers: DocumentHandlers): this;
|
85 | write(chunk: Uint8Array): Promise<void>;
|
86 | end(): Promise<void>;
|
87 | free(): void;
|
88 | }
|