1 | declare namespace parser {
|
2 | type DefaultOptions = {
|
3 | /**
|
4 | * @default false
|
5 | */
|
6 | lowerCaseTags: boolean;
|
7 |
|
8 | /**
|
9 | * @default false
|
10 | */
|
11 | lowerCaseAttributeNames: boolean;
|
12 | };
|
13 |
|
14 | type Directive = {
|
15 | name: string;
|
16 | start: string;
|
17 | end: string;
|
18 | };
|
19 |
|
20 | type Options = {
|
21 | /**
|
22 | * Adds processing of custom directives.
|
23 | * Note: The property `name` in custom directives can be `String` or `RegExp` type.
|
24 | *
|
25 | * @default
|
26 | * [{name: '!doctype', start: '<', end: '>'}]
|
27 | */
|
28 | directives?: Directive[];
|
29 |
|
30 | /**
|
31 | * Indicates whether special tags (`<script>` and `<style>`) should get special treatment and if "empty" tags (eg. `<br>`) can have children.
|
32 | * If `false`, the content of special tags will be text only.
|
33 | * For feeds and other XML content (documents that don't consist of HTML), set this to true.
|
34 | *
|
35 | * @default false
|
36 | */
|
37 | xmlMode?: boolean;
|
38 |
|
39 | /**
|
40 | * If set to `true`, entities within the document will be decoded.
|
41 | *
|
42 | * @default false
|
43 | */
|
44 | decodeEntities?: boolean;
|
45 |
|
46 | /**
|
47 | * If set to `true`, all tags will be lowercased. If `xmlMode` is disabled.
|
48 | *
|
49 | * @default false
|
50 | */
|
51 | lowerCaseTags?: boolean;
|
52 |
|
53 | /**
|
54 | * If set to `true`, all attribute names will be lowercased. This has noticeable impact on speed.
|
55 | *
|
56 | * @default false
|
57 | */
|
58 | lowerCaseAttributeNames?: boolean;
|
59 |
|
60 | /**
|
61 | * If set to true, CDATA sections will be recognized as text even if the `xmlMode` option is not enabled.
|
62 | * NOTE: If `xmlMode` is set to `true` then CDATA sections will always be recognized as text.
|
63 | *
|
64 | * @default false
|
65 | */
|
66 | recognizeCDATA?: boolean;
|
67 |
|
68 | /**
|
69 | * If set to `true`, self-closing tags will trigger the `onclosetag` event even if `xmlMode` is not set to `true`.
|
70 | * NOTE: If `xmlMode` is set to true then self-closing tags will always be recognized.
|
71 | *
|
72 | * @default false
|
73 | */
|
74 | recognizeSelfClosing?: boolean;
|
75 | };
|
76 |
|
77 | type Tree = Node[];
|
78 | type Node = NodeText | NodeTag;
|
79 | type NodeText = string;
|
80 | type NodeTag = {
|
81 | tag: string;
|
82 | attrs?: Attributes;
|
83 | content?: Node[];
|
84 | };
|
85 |
|
86 | type Attributes = Record<string, string>;
|
87 | }
|
88 |
|
89 | declare const parser: {
|
90 | defaultOptions: parser.DefaultOptions;
|
91 | defaultDirectives: parser.Directive[];
|
92 |
|
93 | (content: string, options?: parser.Options): parser.Tree;
|
94 | };
|
95 |
|
96 | export = parser;
|