-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
Tokens.ts
200 lines (174 loc) · 3.86 KB
/
Tokens.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
/* eslint-disable no-use-before-define */
export type Token = (Tokens.Space
| Tokens.Code
| Tokens.Heading
| Tokens.Table
| Tokens.Hr
| Tokens.Blockquote
| Tokens.List
| Tokens.ListItem
| Tokens.Paragraph
| Tokens.HTML
| Tokens.Text
| Tokens.Def
| Tokens.Escape
| Tokens.Tag
| Tokens.Image
| Tokens.Link
| Tokens.Strong
| Tokens.Em
| Tokens.Codespan
| Tokens.Br
| Tokens.Del
| Tokens.Generic) & { loose?: boolean, tokens?: Token[] };
export namespace Tokens {
export interface Space {
type: 'space';
raw: string;
}
export interface Code {
type: 'code';
raw: string;
codeBlockStyle?: 'indented' | undefined;
lang?: string | undefined;
text: string;
escaped?: boolean;
}
export interface Heading {
type: 'heading';
raw: string;
depth: number;
text: string;
tokens: Token[];
}
export interface Table {
type: 'table';
raw: string;
align: Array<'center' | 'left' | 'right' | null>;
header: TableCell[];
rows: TableCell[][];
}
export interface TableCell {
text: string;
tokens?: Token[];
}
export interface Hr {
type: 'hr';
raw: string;
}
export interface Blockquote {
type: 'blockquote';
raw: string;
text: string;
tokens: Token[];
}
export interface List {
type: 'list';
raw: string;
ordered: boolean;
start: number | '';
loose: boolean;
items: ListItem[];
}
export interface ListItem {
type: 'list_item';
raw: string;
task: boolean;
checked?: boolean | undefined;
loose: boolean;
text: string;
tokens?: Token[];
}
export interface Paragraph {
type: 'paragraph';
raw: string;
pre?: boolean | undefined;
text: string;
tokens: Token[];
}
export interface HTML {
type: 'html';
raw: string;
pre: boolean;
text: string;
block: boolean;
}
export interface Text {
type: 'text';
raw: string;
text: string;
tokens?: Token[];
}
export interface Def {
type: 'def';
raw: string;
tag: string;
href: string;
title: string;
}
export interface Escape {
type: 'escape';
raw: string;
text: string;
}
export interface Tag {
type: 'text' | 'html';
raw: string;
inLink: boolean;
inRawBlock: boolean;
text: string;
block: boolean;
}
export interface Link {
type: 'link';
raw: string;
href: string;
title?: string | null;
text: string;
tokens: Token[];
}
export interface Image {
type: 'image';
raw: string;
href: string;
title: string | null;
text: string;
}
export interface Strong {
type: 'strong';
raw: string;
text: string;
tokens: Token[];
}
export interface Em {
type: 'em';
raw: string;
text: string;
tokens: Token[];
}
export interface Codespan {
type: 'codespan';
raw: string;
text: string;
}
export interface Br {
type: 'br';
raw: string;
}
export interface Del {
type: 'del';
raw: string;
text: string;
tokens: Token[];
}
export interface Generic {
[index: string]: any;
type: string;
raw: string;
tokens?: Token[] | undefined;
}
}
export type Links = Record<string, Pick<Tokens.Link | Tokens.Image, 'href' | 'title'>>;
export type TokensList = Token[] & {
links: Links;
};