-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnodeTypes.ts
204 lines (178 loc) · 3.99 KB
/
nodeTypes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// TODO check https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/mdast/index.d.ts
export type Node =
| RootNode
| HeaderNode
| TextNode
| HtmlNode
| ParagraphNode
| StrongNode
| EmphasisNode
| StrikethroughNode
| BlockQuoteNode
| ListItemNode
| OrderedListNode
| UnorderedListNode
| InlineCodeNode
| CodeNode
| ThematicBreakNode
| ImageNode
| ImageReferenceNode
| LinkNode
| LinkReferenceNode
| DefinitionNode
| TableNode;
export interface NodePosition {
line: number;
column: number;
offset: number;
}
export interface NodeBase {
type: string;
position: {
start: NodePosition;
end: NodePosition;
};
children?: Node[];
}
export interface RootNode extends NodeBase {
type: "root";
}
export interface HeaderNode extends NodeBase {
type: "heading";
depth: number;
children: Node[];
}
export interface TextNode extends NodeBase {
type: "text";
value: string;
}
export interface HtmlNode extends NodeBase {
type: "html";
value: string;
}
export interface ParagraphNode extends NodeBase {
type: "paragraph";
children: Node[];
}
export interface StrongNode extends NodeBase {
type: "strong";
children: Node[];
}
export interface EmphasisNode extends NodeBase {
type: "emphasis";
children: Node[];
}
export interface StrikethroughNode extends NodeBase {
type: "delete";
children: Node[];
}
export interface BlockQuoteNode extends NodeBase {
type: "blockquote";
children: Node[];
}
export interface ListNode extends NodeBase {
type: "list";
ordered: boolean;
start: null | number;
/**
* Whether one or more of the children are separated with a blank line from
* its siblings (when `true`), or not (when `false` or not present).
*/
spread: boolean;
children: ListItemNode[];
listLevel: number;
}
export interface OrderedListNode extends ListNode {
ordered: true;
start: number;
}
export interface UnorderedListNode extends ListNode {
ordered: false;
start: null;
}
export interface ListItemNode extends NodeBase {
type: "listItem";
/**
* Whether one or more of the children are separated with a blank line from
* its siblings (when `true`), or not (when `false` or not present).
*/
spread: boolean;
checked: null;
listLevel: number;
children: Node[];
}
export interface InlineCodeNode extends NodeBase {
type: "inlineCode";
value: string;
}
export interface CodeNode extends NodeBase {
type: "code";
value: string;
lang: string;
/** Anything after the language.
*
* \`\`\`ts codeExample title="helloWorld.ts" 6
*
* console.log('alma')
*
* \`\`\`
*
* Gives `meta: 'codeExample title="helloWorld.ts" 6'`
*/
meta: string;
}
export interface ThematicBreakNode extends NodeBase {
type: "thematicBreak";
value: string;
children: never;
}
export interface ImageNode extends NodeBase {
type: "image";
title: string | null;
url: string;
alt: string;
children: never;
}
export interface ImageReferenceNode extends NodeBase {
type: "imageReference";
alt: string;
label: string;
identifier: string;
referenceType: ReferenceType;
}
/**
* Explicitness of a reference.
*
* `'shortcut'`: the reference is implicit, its identifier inferred from its
* content
*
* `'collapsed'`: the reference is explicit, its identifier inferred from its
* content
*
* `'full'`: the reference is explicit, its identifier explicitly set
*/
export type ReferenceType = "shortcut" | "collapsed" | "full";
export interface LinkNode extends NodeBase {
type: "link";
title: string | null;
url: string;
children: Node[];
}
export interface LinkReferenceNode extends NodeBase {
type: "linkReference";
label: string | null;
identifier: string;
referenceType: ReferenceType;
children: Node[];
}
export interface DefinitionNode extends NodeBase {
type: "definition";
label: string | null;
identifier: string;
title: string | null;
url: string;
}
export interface TableNode extends NodeBase {
type: "table";
children: Node[];
}