-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
index.js
39 lines (34 loc) · 1.14 KB
/
index.js
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
/**
* @typedef {import('mdast').Root} Root
* @typedef {import('micromark-extension-mdxjs').Options} MicromarkOptions
* @typedef {import('mdast-util-mdx').ToMarkdownOptions} ToMarkdownOptions
* @typedef {MicromarkOptions & ToMarkdownOptions} Options
*
* @typedef {import('mdast-util-mdx')} DoNotTouchAsThisImportItIncludesMdxInTree
*/
import {mdxjs} from 'micromark-extension-mdxjs'
import {mdxFromMarkdown, mdxToMarkdown} from 'mdast-util-mdx'
/**
* Plugin to support MDX (import/exports: `export {x} from 'y'`; expressions:
* `{1 + 1}`; and JSX: `<Video id={123} />`).
*
* @type {import('unified').Plugin<[Options?]|Array<void>, Root>}
*/
export default function remarkMdx(options = {}) {
const data = this.data()
add('micromarkExtensions', mdxjs(options))
add('fromMarkdownExtensions', mdxFromMarkdown())
add('toMarkdownExtensions', mdxToMarkdown(options))
/**
* @param {string} field
* @param {unknown} value
*/
function add(field, value) {
const list = /** @type {Array<unknown>} */ (
// Other extensions
/* c8 ignore next 2 */
data[field] ? data[field] : (data[field] = [])
)
list.push(value)
}
}