1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | import type { ASTNodeTypes } from "./ASTNodeTypes";
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export type TxtNodeType = keyof typeof ASTNodeTypes;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export type AnyTxtNode = TxtNode | TxtTextNode | TxtParentNode;
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | export type TxtNodePosition = {
|
29 | line: number;
|
30 | column: number;
|
31 | };
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | export type TxtNodeLocation = {
|
37 | start: TxtNodePosition;
|
38 | end: TxtNodePosition;
|
39 | };
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | export type TxtNodeRange = readonly [startIndex: number, endIndex: number];
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | export interface TxtNode {
|
51 | type: TxtNodeType;
|
52 | raw: string;
|
53 | range: TxtNodeRange;
|
54 | loc: TxtNodeLocation;
|
55 |
|
56 | parent?: TxtParentNode;
|
57 |
|
58 | [index: string]: any;
|
59 | }
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | export interface TxtTextNode extends TxtNode {
|
67 | value: string;
|
68 | }
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | export interface TxtParentNode extends TxtNode {
|
75 | children: Content[];
|
76 | }
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | export type AlignType = "left" | "right" | "center" | null;
|
82 | export type ReferenceType = "shortcut" | "collapsed" | "full";
|
83 |
|
84 | export type Content = TopLevelContent | ListContent | TableContent | RowContent | PhrasingContent;
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | export type TopLevelContent = BlockContent;
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | export type BlockContent =
|
95 | | TxtParagraphNode
|
96 | | TxtHeaderNode
|
97 | | TxtHorizontalRuleNode
|
98 | | TxtBlockQuoteNode
|
99 | | TxtListNode
|
100 | | TxtTableNode
|
101 | | TxtHtmlNode
|
102 | | TxtCodeBlockNode;
|
103 |
|
104 |
|
105 |
|
106 | export type ListContent = TxtListItemNode;
|
107 |
|
108 |
|
109 |
|
110 | export type TableContent = TxtTableRowNode;
|
111 |
|
112 |
|
113 |
|
114 | export type RowContent = TxtTableCellNode;
|
115 |
|
116 |
|
117 |
|
118 | export type PhrasingContent = TxtLinkNode | StaticPhrasingContent;
|
119 |
|
120 |
|
121 |
|
122 | export type StaticPhrasingContent =
|
123 | | TxtStrNode
|
124 | | TxtEmphasisNode
|
125 | | TxtStrongNode
|
126 | | TxtDeleteNode
|
127 | | TxtHtmlNode
|
128 | | TxtCodeNode
|
129 | | TxtBreakNode
|
130 | | TxtImageNode;
|
131 |
|
132 | export interface TxtDocumentNode extends TxtParentNode {
|
133 | type: "Document";
|
134 | }
|
135 |
|
136 | export interface TxtParagraphNode extends TxtParentNode {
|
137 | type: "Paragraph";
|
138 | children: PhrasingContent[];
|
139 | }
|
140 |
|
141 | export interface TxtHeaderNode extends TxtParentNode {
|
142 | type: "Header";
|
143 | depth: 1 | 2 | 3 | 4 | 5 | 6;
|
144 | children: PhrasingContent[];
|
145 | }
|
146 |
|
147 | export interface TxtHorizontalRuleNode extends TxtNode {
|
148 | type: "HorizontalRule";
|
149 | }
|
150 |
|
151 | export interface TxtBlockQuoteNode extends TxtParentNode {
|
152 | type: "BlockQuote";
|
153 | children: BlockContent[];
|
154 | }
|
155 |
|
156 | export interface TxtListNode extends TxtParentNode {
|
157 | type: "List";
|
158 | ordered?: boolean | null | undefined;
|
159 | start?: number | null | undefined;
|
160 | spread?: boolean | null | undefined;
|
161 | children: ListContent[];
|
162 | }
|
163 |
|
164 | export interface TxtListItemNode extends TxtParentNode {
|
165 | type: "ListItem";
|
166 | checked?: boolean | null | undefined;
|
167 | spread?: boolean | null | undefined;
|
168 | children: BlockContent[];
|
169 | }
|
170 |
|
171 | export interface TxtTableNode extends TxtParentNode {
|
172 | type: "Table";
|
173 | align?: AlignType[] | null | undefined;
|
174 | children: TableContent[];
|
175 | }
|
176 |
|
177 | export interface TxtTableRowNode extends TxtParentNode {
|
178 | type: "TableRow";
|
179 | children: RowContent[];
|
180 | }
|
181 |
|
182 | export interface TxtTableCellNode extends TxtParentNode {
|
183 | type: "TableCell";
|
184 | children: PhrasingContent[];
|
185 | }
|
186 |
|
187 | export interface TxtHtmlNode extends TxtTextNode {
|
188 | type: "Html";
|
189 | }
|
190 |
|
191 | export interface TxtCommentNode extends TxtTextNode {
|
192 | type: "Comment";
|
193 | }
|
194 |
|
195 | export interface TxtCodeBlockNode extends TxtTextNode {
|
196 | type: "CodeBlock";
|
197 | lang?: string | null | undefined;
|
198 | meta?: string | null | undefined;
|
199 | }
|
200 |
|
201 | export interface TxtStrNode extends TxtTextNode {
|
202 | type: "Str";
|
203 | }
|
204 |
|
205 | export interface TxtEmphasisNode extends TxtParentNode {
|
206 | type: "Emphasis";
|
207 | children: PhrasingContent[];
|
208 | }
|
209 |
|
210 | export interface TxtStrongNode extends TxtParentNode {
|
211 | type: "Strong";
|
212 | children: PhrasingContent[];
|
213 | }
|
214 |
|
215 | export interface TxtDeleteNode extends TxtParentNode {
|
216 | type: "Delete";
|
217 | children: PhrasingContent[];
|
218 | }
|
219 |
|
220 |
|
221 | export interface TxtCodeNode extends TxtTextNode {
|
222 | type: "Code";
|
223 | }
|
224 |
|
225 | export interface TxtBreakNode extends TxtNode {
|
226 | type: "Break";
|
227 | }
|
228 |
|
229 | export interface TxtLinkNode extends TxtParentNode, TxtResource {
|
230 | type: "Link";
|
231 | children: StaticPhrasingContent[];
|
232 | }
|
233 |
|
234 | export interface TxtImageNode extends TxtNode, TxtResource, TxtAlternative {
|
235 | type: "Image";
|
236 | }
|
237 |
|
238 |
|
239 | export interface TxtResource {
|
240 | url: string;
|
241 | title?: string | null | undefined;
|
242 | }
|
243 |
|
244 | export interface TxtAlternative {
|
245 | alt?: string | null | undefined;
|
246 | }
|