summaryrefslogtreecommitdiff
path: root/packages/markdown/remark/src/mdxjs.ts
blob: c3a9849ea97a8e1fb25a82ca506ec1c85de783ea (plain) (blame)
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
// 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.

import { mdxJsx } from '@astrojs/micromark-extension-mdx-jsx';
import { Parser } from 'acorn';
import acornJsx from 'acorn-jsx';
import type { Options } from 'micromark-extension-mdx-expression';
import { mdxExpression } from 'micromark-extension-mdx-expression';
import { mdxMd } from 'micromark-extension-mdx-md';
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' },
			addResult: true,
		},
		options
	);

	return combineExtensions([mdxExpression(settings), mdxJsx(settings), mdxMd]);
}