UNPKG

8.46 kBTypeScriptView Raw
1// Type definitions for Mdast 3.0
2// Project: https://github.com/syntax-tree/mdast, https://github.com/wooorm/mdast
3// Definitions by: Christian Murphy <https://github.com/ChristianMurphy>
4// Jun Lu <https://github.com/lujun2>
5// Remco Haszing <https://github.com/remcohaszing>
6// Titus Wormer <https://github.com/wooorm>
7// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
8// TypeScript Version: 3.0
9
10import { Parent as UnistParent, Literal as UnistLiteral, Node } from 'unist';
11
12export type AlignType = 'left' | 'right' | 'center' | null;
13
14export type ReferenceType = 'shortcut' | 'collapsed' | 'full';
15
16/**
17 * This map registers all node types that may be used where markdown block content is accepted.
18 *
19 * These types are accepted inside block quotes, list items, footnotes, and roots.
20 *
21 * This interface can be augmented to register custom node types.
22 *
23 * @example
24 * declare module 'mdast' {
25 * interface BlockContentMap {
26 * // Allow using math nodes defined by `remark-math`.
27 * math: Math;
28 * }
29 * }
30 */
31export interface BlockContentMap {
32 paragraph: Paragraph;
33 heading: Heading;
34 thematicBreak: ThematicBreak;
35 blockquote: Blockquote;
36 list: List;
37 table: Table;
38 html: HTML;
39 code: Code;
40}
41
42/**
43 * This map registers all frontmatter node types.
44 *
45 * This interface can be augmented to register custom node types.
46 *
47 * @example
48 * declare module 'mdast' {
49 * interface FrontmatterContentMap {
50 * // Allow using toml nodes defined by `remark-frontmatter`.
51 * toml: TOML;
52 * }
53 * }
54 */
55export interface FrontmatterContentMap {
56 yaml: YAML;
57}
58
59/**
60 * This map registers all node definition types.
61 *
62 * This interface can be augmented to register custom node types.
63 *
64 * @example
65 * declare module 'mdast' {
66 * interface DefinitionContentMap {
67 * custom: Custom;
68 * }
69 * }
70 */
71export interface DefinitionContentMap {
72 definition: Definition;
73 footnoteDefinition: FootnoteDefinition;
74}
75
76/**
77 * This map registers all node types that are acceptable in a static phrasing context.
78 *
79 * This interface can be augmented to register custom node types in a phrasing context, including links and link
80 * references.
81 *
82 * @example
83 * declare module 'mdast' {
84 * interface StaticPhrasingContentMap {
85 * mdxJsxTextElement: MDXJSXTextElement;
86 * }
87 * }
88 */
89export interface StaticPhrasingContentMap {
90 text: Text;
91 emphasis: Emphasis;
92 strong: Strong;
93 delete: Delete;
94 html: HTML;
95 inlineCode: InlineCode;
96 break: Break;
97 image: Image;
98 imageReference: ImageReference;
99 footnote: Footnote;
100 footnoteReference: FootnoteReference;
101}
102
103/**
104 * This map registers all node types that are acceptable in a (interactive) phrasing context (so not in links).
105 *
106 * This interface can be augmented to register custom node types in a phrasing context, excluding links and link
107 * references.
108 *
109 * @example
110 * declare module 'mdast' {
111 * interface PhrasingContentMap {
112 * custom: Custom;
113 * }
114 * }
115 */
116export interface PhrasingContentMap extends StaticPhrasingContentMap {
117 link: Link;
118 linkReference: LinkReference;
119}
120
121/**
122 * This map registers all node types that are acceptable inside lists.
123 *
124 * This interface can be augmented to register custom node types that are acceptable inside lists.
125 *
126 * @example
127 * declare module 'mdast' {
128 * interface ListContentMap {
129 * custom: Custom;
130 * }
131 * }
132 */
133export interface ListContentMap {
134 listItem: ListItem;
135}
136
137/**
138 * This map registers all node types that are acceptable inside tables (not table cells).
139 *
140 * This interface can be augmented to register custom node types that are acceptable inside tables.
141 *
142 * @example
143 * declare module 'mdast' {
144 * interface TableContentMap {
145 * custom: Custom;
146 * }
147 * }
148 */
149export interface TableContentMap {
150 tableRow: TableRow;
151}
152
153/**
154 * This map registers all node types that are acceptable inside tables rows (not table cells).
155 *
156 * This interface can be augmented to register custom node types that are acceptable inside table rows.
157 *
158 * @example
159 * declare module 'mdast' {
160 * interface RowContentMap {
161 * custom: Custom;
162 * }
163 * }
164 */
165export interface RowContentMap {
166 tableCell: TableCell;
167}
168
169export type Content = TopLevelContent | ListContent | TableContent | RowContent | PhrasingContent;
170
171export type TopLevelContent = BlockContent | FrontmatterContent | DefinitionContent;
172
173export type BlockContent = BlockContentMap[keyof BlockContentMap];
174
175export type FrontmatterContent = FrontmatterContentMap[keyof FrontmatterContentMap];
176
177export type DefinitionContent = DefinitionContentMap[keyof DefinitionContentMap];
178
179export type ListContent = ListContentMap[keyof ListContentMap];
180
181export type TableContent = TableContentMap[keyof TableContentMap];
182
183export type RowContent = RowContentMap[keyof RowContentMap];
184
185export type PhrasingContent = PhrasingContentMap[keyof PhrasingContentMap];
186
187export type StaticPhrasingContent = StaticPhrasingContentMap[keyof StaticPhrasingContentMap];
188
189export interface Parent extends UnistParent {
190 children: Content[];
191}
192
193export interface Literal extends UnistLiteral {
194 value: string;
195}
196
197export interface Root extends Parent {
198 type: 'root';
199}
200
201export interface Paragraph extends Parent {
202 type: 'paragraph';
203 children: PhrasingContent[];
204}
205
206export interface Heading extends Parent {
207 type: 'heading';
208 depth: 1 | 2 | 3 | 4 | 5 | 6;
209 children: PhrasingContent[];
210}
211
212export interface ThematicBreak extends Node {
213 type: 'thematicBreak';
214}
215
216export interface Blockquote extends Parent {
217 type: 'blockquote';
218 children: Array<BlockContent | DefinitionContent>;
219}
220
221export interface List extends Parent {
222 type: 'list';
223 ordered?: boolean | null | undefined;
224 start?: number | null | undefined;
225 spread?: boolean | null | undefined;
226 children: ListContent[];
227}
228
229export interface ListItem extends Parent {
230 type: 'listItem';
231 checked?: boolean | null | undefined;
232 spread?: boolean | null | undefined;
233 children: Array<BlockContent | DefinitionContent>;
234}
235
236export interface Table extends Parent {
237 type: 'table';
238 align?: AlignType[] | null | undefined;
239 children: TableContent[];
240}
241
242export interface TableRow extends Parent {
243 type: 'tableRow';
244 children: RowContent[];
245}
246
247export interface TableCell extends Parent {
248 type: 'tableCell';
249 children: PhrasingContent[];
250}
251
252export interface HTML extends Literal {
253 type: 'html';
254}
255
256export interface Code extends Literal {
257 type: 'code';
258 lang?: string | null | undefined;
259 meta?: string | null | undefined;
260}
261
262export interface YAML extends Literal {
263 type: 'yaml';
264}
265
266export interface Definition extends Node, Association, Resource {
267 type: 'definition';
268}
269
270export interface FootnoteDefinition extends Parent, Association {
271 type: 'footnoteDefinition';
272 children: Array<BlockContent | DefinitionContent>;
273}
274
275export interface Text extends Literal {
276 type: 'text';
277}
278
279export interface Emphasis extends Parent {
280 type: 'emphasis';
281 children: PhrasingContent[];
282}
283
284export interface Strong extends Parent {
285 type: 'strong';
286 children: PhrasingContent[];
287}
288
289export interface Delete extends Parent {
290 type: 'delete';
291 children: PhrasingContent[];
292}
293
294export interface InlineCode extends Literal {
295 type: 'inlineCode';
296}
297
298export interface Break extends Node {
299 type: 'break';
300}
301
302export interface Link extends Parent, Resource {
303 type: 'link';
304 children: StaticPhrasingContent[];
305}
306
307export interface Image extends Node, Resource, Alternative {
308 type: 'image';
309}
310
311export interface LinkReference extends Parent, Reference {
312 type: 'linkReference';
313 children: StaticPhrasingContent[];
314}
315
316export interface ImageReference extends Node, Reference, Alternative {
317 type: 'imageReference';
318}
319
320export interface Footnote extends Parent {
321 type: 'footnote';
322 children: PhrasingContent[];
323}
324
325export interface FootnoteReference extends Node, Association {
326 type: 'footnoteReference';
327}
328
329// Mixin
330export interface Resource {
331 url: string;
332 title?: string | null | undefined;
333}
334
335export interface Association {
336 identifier: string;
337 label?: string | null | undefined;
338}
339
340export interface Reference extends Association {
341 referenceType: ReferenceType;
342}
343
344export interface Alternative {
345 alt?: string | null | undefined;
346}