1 | import { Literal as UnistLiteral, Node as UnistNode, Parent as UnistParent } from "unist";
|
---|
2 |
|
---|
3 | export { UnistNode as Node };
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * This map registers all node types that may be used as top-level content in the document.
|
---|
7 | *
|
---|
8 | * These types are accepted inside `root` nodes.
|
---|
9 | *
|
---|
10 | * This interface can be augmented to register custom node types.
|
---|
11 | *
|
---|
12 | * @example
|
---|
13 | * declare module 'hast' {
|
---|
14 | * interface RootContentMap {
|
---|
15 | * // Allow using raw nodes defined by `rehype-raw`.
|
---|
16 | * raw: Raw;
|
---|
17 | * }
|
---|
18 | * }
|
---|
19 | */
|
---|
20 | export interface RootContentMap {
|
---|
21 | comment: Comment;
|
---|
22 | doctype: DocType;
|
---|
23 | element: Element;
|
---|
24 | text: Text;
|
---|
25 | }
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * This map registers all node types that may be used as content in an element.
|
---|
29 | *
|
---|
30 | * These types are accepted inside `element` nodes.
|
---|
31 | *
|
---|
32 | * This interface can be augmented to register custom node types.
|
---|
33 | *
|
---|
34 | * @example
|
---|
35 | * declare module 'hast' {
|
---|
36 | * interface RootContentMap {
|
---|
37 | * custom: Custom;
|
---|
38 | * }
|
---|
39 | * }
|
---|
40 | */
|
---|
41 | export interface ElementContentMap {
|
---|
42 | comment: Comment;
|
---|
43 | element: Element;
|
---|
44 | text: Text;
|
---|
45 | }
|
---|
46 |
|
---|
47 | export type Content = RootContent | ElementContent;
|
---|
48 |
|
---|
49 | export type RootContent = RootContentMap[keyof RootContentMap];
|
---|
50 |
|
---|
51 | export type ElementContent = ElementContentMap[keyof ElementContentMap];
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Node in hast containing other nodes.
|
---|
55 | */
|
---|
56 | export interface Parent extends UnistParent {
|
---|
57 | /**
|
---|
58 | * List representing the children of a node.
|
---|
59 | */
|
---|
60 | children: Content[];
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Nodes in hast containing a value.
|
---|
65 | */
|
---|
66 | export interface Literal extends UnistLiteral {
|
---|
67 | value: string;
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Root represents a document.
|
---|
72 | * Can be used as the root of a tree, or as a value of the
|
---|
73 | * content field on a 'template' Element, never as a child.
|
---|
74 | */
|
---|
75 | export interface Root extends Parent {
|
---|
76 | /**
|
---|
77 | * Represents this variant of a Node.
|
---|
78 | */
|
---|
79 | type: "root";
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * List representing the children of a node.
|
---|
83 | */
|
---|
84 | children: RootContent[];
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Element represents an HTML Element.
|
---|
89 | */
|
---|
90 | export interface Element extends Parent {
|
---|
91 | /**
|
---|
92 | * Represents this variant of a Node.
|
---|
93 | */
|
---|
94 | type: "element";
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Represents the element’s local name.
|
---|
98 | */
|
---|
99 | tagName: string;
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Represents information associated with the element.
|
---|
103 | */
|
---|
104 | properties?: Properties | undefined;
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * If the tagName field is 'template', a content field can be present.
|
---|
108 | */
|
---|
109 | content?: Root | undefined;
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * List representing the children of a node.
|
---|
113 | */
|
---|
114 | children: ElementContent[];
|
---|
115 | }
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Represents information associated with an element.
|
---|
119 | */
|
---|
120 | export interface Properties {
|
---|
121 | [PropertyName: string]: boolean | number | string | null | undefined | Array<string | number>;
|
---|
122 | }
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Represents an HTML DocumentType.
|
---|
126 | */
|
---|
127 | export interface DocType extends UnistNode {
|
---|
128 | /**
|
---|
129 | * Represents this variant of a Node.
|
---|
130 | */
|
---|
131 | type: "doctype";
|
---|
132 |
|
---|
133 | name: string;
|
---|
134 | }
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Represents an HTML Comment.
|
---|
138 | */
|
---|
139 | export interface Comment extends Literal {
|
---|
140 | /**
|
---|
141 | * Represents this variant of a Literal.
|
---|
142 | */
|
---|
143 | type: "comment";
|
---|
144 | }
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Represents an HTML Text.
|
---|
148 | */
|
---|
149 | export interface Text extends Literal {
|
---|
150 | /**
|
---|
151 | * Represents this variant of a Literal.
|
---|
152 | */
|
---|
153 | type: "text";
|
---|
154 | }
|
---|