|
1 | 1 | /** |
2 | | - * @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext |
3 | | - * @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension |
4 | | - * @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle |
5 | | - * @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension |
6 | | - * @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle |
7 | | - * @typedef {import('estree-jsx').Program} Program |
8 | 2 | * @typedef {import('./complex-types.js').MdxFlowExpression} MdxFlowExpression |
9 | 3 | * @typedef {import('./complex-types.js').MdxTextExpression} MdxTextExpression |
10 | 4 | */ |
11 | 5 |
|
12 | 6 | /** |
13 | 7 | * @typedef {MdxFlowExpression} MDXFlowExpression |
| 8 | + * Deprecated: use `MdxFlowExpression`. |
14 | 9 | * @typedef {MdxTextExpression} MDXTextExpression |
| 10 | + * Deprecated: use `MdxFlowExpression`. |
15 | 11 | */ |
16 | 12 |
|
17 | | -/** @type {FromMarkdownExtension} */ |
18 | | -export const mdxExpressionFromMarkdown = { |
19 | | - enter: { |
20 | | - mdxFlowExpression: enterMdxFlowExpression, |
21 | | - mdxTextExpression: enterMdxTextExpression |
22 | | - }, |
23 | | - exit: { |
24 | | - mdxFlowExpression: exitMdxExpression, |
25 | | - mdxFlowExpressionChunk: exitMdxExpressionData, |
26 | | - mdxTextExpression: exitMdxExpression, |
27 | | - mdxTextExpressionChunk: exitMdxExpressionData |
28 | | - } |
29 | | -} |
30 | | - |
31 | | -/** @type {ToMarkdownExtension} */ |
32 | | -export const mdxExpressionToMarkdown = { |
33 | | - handlers: { |
34 | | - mdxFlowExpression: handleMdxExpression, |
35 | | - mdxTextExpression: handleMdxExpression |
36 | | - }, |
37 | | - unsafe: [ |
38 | | - {character: '{', inConstruct: ['phrasing']}, |
39 | | - {atBreak: true, character: '{'} |
40 | | - ] |
41 | | -} |
42 | | - |
43 | | -/** |
44 | | - * @this {CompileContext} |
45 | | - * @type {FromMarkdownHandle} |
46 | | - */ |
47 | | -function enterMdxFlowExpression(token) { |
48 | | - this.enter({type: 'mdxFlowExpression', value: ''}, token) |
49 | | - this.buffer() |
50 | | -} |
51 | | - |
52 | | -/** |
53 | | - * @this {CompileContext} |
54 | | - * @type {FromMarkdownHandle} |
55 | | - */ |
56 | | -function enterMdxTextExpression(token) { |
57 | | - this.enter({type: 'mdxTextExpression', value: ''}, token) |
58 | | - this.buffer() |
59 | | -} |
60 | | - |
61 | | -/** |
62 | | - * @this {CompileContext} |
63 | | - * @type {FromMarkdownHandle} |
64 | | - */ |
65 | | -function exitMdxExpression(token) { |
66 | | - const value = this.resume() |
67 | | - /** @type {Program|undefined} */ |
68 | | - // @ts-expect-error: estree. |
69 | | - const estree = token.estree |
70 | | - const node = /** @type {MDXFlowExpression|MDXTextExpression} */ ( |
71 | | - this.exit(token) |
72 | | - ) |
73 | | - node.value = value |
74 | | - |
75 | | - if (estree) { |
76 | | - node.data = {estree} |
77 | | - } |
78 | | -} |
79 | | - |
80 | | -/** |
81 | | - * @this {CompileContext} |
82 | | - * @type {FromMarkdownHandle} |
83 | | - */ |
84 | | -function exitMdxExpressionData(token) { |
85 | | - this.config.enter.data.call(this, token) |
86 | | - this.config.exit.data.call(this, token) |
87 | | -} |
88 | | - |
89 | | -/** |
90 | | - * @type {ToMarkdownHandle} |
91 | | - * @param {MDXFlowExpression|MDXTextExpression} node |
92 | | - */ |
93 | | -function handleMdxExpression(node) { |
94 | | - const value = node.value || '' |
95 | | - return '{' + value + '}' |
96 | | -} |
| 13 | +export { |
| 14 | + mdxExpressionFromMarkdown, |
| 15 | + mdxExpressionToMarkdown |
| 16 | +} from './lib/index.js' |
0 commit comments