-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.d.ts
344 lines (315 loc) · 7.12 KB
/
index.d.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
import type {Program} from 'estree-jsx'
import type {Data as HastData, ElementContent, Parent as HastParent} from 'hast'
import type {
BlockContent,
Data as MdastData,
DefinitionContent,
Parent as MdastParent,
PhrasingContent
} from 'mdast'
import type {Data, Node} from 'unist'
import type {Tag} from './lib/index.js'
// Expose JavaScript API.
export {mdxJsxFromMarkdown, mdxJsxToMarkdown} from './lib/index.js'
// Expose options.
export type {ToMarkdownOptions} from './lib/index.js'
// Expose node types.
/**
* MDX JSX attribute value set to an expression.
*
* ```markdown
* > | <a b={c} />
* ^^^
* ```
*/
export interface MdxJsxAttributeValueExpression extends Node {
/**
* Node type.
*/
type: 'mdxJsxAttributeValueExpression'
/**
* Value.
*/
value: string
/**
* Data associated with the mdast MDX JSX attribute value expression.
*/
data?: MdxJsxAttributeValueExpressionData | undefined
}
/**
* Info associated with mdast MDX JSX attribute value expression nodes by the
* ecosystem.
*/
export interface MdxJsxAttributeValueExpressionData extends Data {
/**
* Program node from estree.
*/
estree?: Program | null | undefined
}
/**
* MDX JSX attribute as an expression.
*
* ```markdown
* > | <a {...b} />
* ^^^^^^
* ```
*/
export interface MdxJsxExpressionAttribute extends Node {
/**
* Node type.
*/
type: 'mdxJsxExpressionAttribute'
/**
* Value.
*/
value: string
/**
* Data associated with the mdast MDX JSX expression attributes.
*/
data?: MdxJsxExpressionAttributeData | undefined
}
/**
* Info associated with mdast MDX JSX expression attribute nodes by the
* ecosystem.
*/
export interface MdxJsxExpressionAttributeData extends Data {
/**
* Program node from estree.
*/
estree?: Program | null | undefined
}
/**
* MDX JSX attribute with a key.
*
* ```markdown
* > | <a b="c" />
* ^^^^^
* ```
*/
export interface MdxJsxAttribute extends Node {
/**
* Node type.
*/
type: 'mdxJsxAttribute'
/**
* Attribute name.
*/
name: string
/**
* Attribute value.
*/
value?: MdxJsxAttributeValueExpression | string | null | undefined
/**
* Data associated with the mdast MDX JSX attribute.
*/
data?: MdxJsxAttributeData | undefined
}
/**
* Info associated with mdast MDX JSX attribute nodes by the
* ecosystem.
*/
export interface MdxJsxAttributeData extends Data {}
/**
* MDX JSX element node, occurring in flow (block).
*/
export interface MdxJsxFlowElement extends MdastParent {
/**
* Node type.
*/
type: 'mdxJsxFlowElement'
/**
* MDX JSX element name (`null` for fragments).
*/
name: string | null
/**
* MDX JSX element attributes.
*/
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
/**
* Content.
*/
children: Array<BlockContent | DefinitionContent>
/**
* Data associated with the mdast MDX JSX elements (flow).
*/
data?: MdxJsxFlowElementData | undefined
}
/**
* Info associated with mdast MDX JSX element (flow) nodes by the
* ecosystem.
*/
export interface MdxJsxFlowElementData extends MdastData {}
/**
* MDX JSX element node, occurring in text (phrasing).
*/
export interface MdxJsxTextElement extends MdastParent {
/**
* Node type.
*/
type: 'mdxJsxTextElement'
/**
* MDX JSX element name (`null` for fragments).
*/
name: string | null
/**
* MDX JSX element attributes.
*/
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
/**
* Content.
*/
children: PhrasingContent[]
/**
* Data associated with the mdast MDX JSX elements (text).
*/
data?: MdxJsxTextElementData | undefined
}
/**
* Info associated with mdast MDX JSX element (text) nodes by the
* ecosystem.
*/
export interface MdxJsxTextElementData extends MdastData {}
/**
* MDX JSX element node, occurring in flow (block), for hast.
*/
export interface MdxJsxFlowElementHast extends HastParent {
/**
* Node type.
*/
type: 'mdxJsxFlowElement'
/**
* MDX JSX element name (`null` for fragments).
*/
name: string | null
/**
* MDX JSX element attributes.
*/
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
/**
* Content.
*/
children: ElementContent[]
/**
* Data associated with the hast MDX JSX elements (flow).
*/
data?: MdxJsxFlowElementHastData | undefined
}
/**
* Info associated with hast MDX JSX element (flow) nodes by the
* ecosystem.
*/
export interface MdxJsxFlowElementHastData extends HastData {}
/**
* MDX JSX element node, occurring in text (phrasing), for hast.
*/
export interface MdxJsxTextElementHast extends HastParent {
/**
* Node type.
*/
type: 'mdxJsxTextElement'
/**
* MDX JSX element name (`null` for fragments).
*/
name: string | null
/**
* MDX JSX element attributes.
*/
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
/**
* Content.
*/
children: ElementContent[]
/**
* Data associated with the hast MDX JSX elements (text).
*/
data?: MdxJsxTextElementHastData | undefined
}
/**
* Info associated with hast MDX JSX element (text) nodes by the
* ecosystem.
*/
export interface MdxJsxTextElementHastData extends HastData {}
// Add nodes to mdast content.
declare module 'mdast' {
interface BlockContentMap {
/**
* MDX JSX element node, occurring in flow (block).
*/
mdxJsxFlowElement: MdxJsxFlowElement
}
interface PhrasingContentMap {
/**
* MDX JSX element node, occurring in text (phrasing).
*/
mdxJsxTextElement: MdxJsxTextElement
}
interface RootContentMap {
/**
* MDX JSX element node, occurring in flow (block).
*/
mdxJsxFlowElement: MdxJsxFlowElement
/**
* MDX JSX element node, occurring in text (phrasing).
*/
mdxJsxTextElement: MdxJsxTextElement
}
}
// Add nodes to hast content.
declare module 'hast' {
interface ElementContentMap {
/**
* MDX JSX element node, occurring in text (phrasing).
*/
mdxJsxTextElement: MdxJsxTextElementHast
/**
* MDX JSX element node, occurring in flow (block).
*/
mdxJsxFlowElement: MdxJsxFlowElementHast
}
interface RootContentMap {
/**
* MDX JSX element node, occurring in text (phrasing).
*/
mdxJsxTextElement: MdxJsxTextElementHast
/**
* MDX JSX element node, occurring in flow (block).
*/
mdxJsxFlowElement: MdxJsxFlowElementHast
}
}
// Add custom data tracked to turn markdown into a tree.
declare module 'mdast-util-from-markdown' {
interface CompileData {
/**
* Current MDX JSX tag.
*/
mdxJsxTag?: Tag | undefined
/**
* Current stack of open MDX JSX tags.
*/
mdxJsxTagStack?: Tag[] | undefined
}
}
// Add custom data tracked to turn a syntax tree into markdown.
declare module 'mdast-util-to-markdown' {
interface ConstructNameMap {
/**
* Whole JSX element, in flow.
*
* ```markdown
* > | <a />
* ^^^^^
* ```
*/
mdxJsxFlowElement: 'mdxJsxFlowElement'
/**
* Whole JSX element, in text.
*
* ```markdown
* > | a <b />.
* ^^^^^
* ```
*/
mdxJsxTextElement: 'mdxJsxTextElement'
}
}