0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/markdown/remark/src/mdxjs.ts

28 lines
1.1 KiB
TypeScript
Raw Normal View History

// 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';
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';
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';
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,
},
options
);
2022-06-08 12:43:10 -05:00
return combineExtensions([mdxExpression(settings), mdxJsx(settings), mdxMd]);
}