2022-06-08 12:41:36 -05:00
|
|
|
// Note: The code in this file is based on `micromark-extension-mdxjs`
|
|
|
|
// and was adapted to use our fork `@astrojs/micromark-extension-mdx-jsx`
|
|
|
|
// instead of `micromark-extension-mdx-jsx` to allow some extended syntax.
|
|
|
|
// See `@astrojs/micromark-extension-mdx-jsx` on NPM for more details.
|
|
|
|
// Also, support for ESM imports & exports in Markdown content was removed.
|
|
|
|
|
2022-06-08 12:43:10 -05:00
|
|
|
import { mdxJsx } from '@astrojs/micromark-extension-mdx-jsx';
|
2022-06-08 12:41:36 -05:00
|
|
|
import { Parser } from 'acorn';
|
|
|
|
import acornJsx from 'acorn-jsx';
|
2022-06-08 12:43:10 -05:00
|
|
|
import type { Options } from 'micromark-extension-mdx-expression';
|
2022-06-08 12:41:36 -05:00
|
|
|
import { mdxExpression } from 'micromark-extension-mdx-expression';
|
|
|
|
import { mdxMd } from 'micromark-extension-mdx-md';
|
2022-06-08 12:43:10 -05:00
|
|
|
import { combineExtensions } from 'micromark-util-combine-extensions';
|
2022-06-08 12:41:36 -05:00
|
|
|
import type { Extension } from 'micromark-util-types';
|
|
|
|
|
|
|
|
export function mdxjs(options: Options): Extension {
|
|
|
|
const settings: any = Object.assign(
|
|
|
|
{
|
|
|
|
acorn: Parser.extend(acornJsx()),
|
|
|
|
acornOptions: { ecmaVersion: 2020, sourceType: 'module' },
|
2022-06-08 12:43:10 -05:00
|
|
|
addResult: true,
|
2022-06-08 12:41:36 -05:00
|
|
|
},
|
|
|
|
options
|
|
|
|
);
|
|
|
|
|
2022-06-08 12:43:10 -05:00
|
|
|
return combineExtensions([mdxExpression(settings), mdxJsx(settings), mdxMd]);
|
2022-06-08 12:41:36 -05:00
|
|
|
}
|