summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/src/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/mdx/src/index.ts')
-rw-r--r--packages/integrations/mdx/src/index.ts24
1 files changed, 22 insertions, 2 deletions
diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts
index 140e86632..af63c4ad2 100644
--- a/packages/integrations/mdx/src/index.ts
+++ b/packages/integrations/mdx/src/index.ts
@@ -1,9 +1,26 @@
-import mdxPlugin from '@mdx-js/rollup';
+import mdxPlugin, { Options as MdxRollupPluginOptions } from '@mdx-js/rollup';
import type { AstroIntegration } from 'astro';
import { parse as parseESM } from 'es-module-lexer';
+import remarkGfm from 'remark-gfm';
+import remarkSmartypants from 'remark-smartypants';
import { getFileInfo } from './utils.js';
-export default function mdx(): AstroIntegration {
+type WithExtends<T> = T | { extends: T };
+
+type MdxOptions = {
+ remarkPlugins?: WithExtends<MdxRollupPluginOptions['remarkPlugins']>;
+ rehypePlugins?: WithExtends<MdxRollupPluginOptions['rehypePlugins']>;
+}
+
+const DEFAULT_REMARK_PLUGINS = [remarkGfm, remarkSmartypants];
+
+function handleExtends<T>(config: WithExtends<T[] | undefined>, defaults: T[] = []): T[] | undefined {
+ if (Array.isArray(config)) return config;
+
+ return [...defaults, ...(config?.extends ?? [])];
+}
+
+export default function mdx(mdxOptions: MdxOptions = {}): AstroIntegration {
return {
name: '@astrojs/mdx',
hooks: {
@@ -15,6 +32,9 @@ export default function mdx(): AstroIntegration {
{
enforce: 'pre',
...mdxPlugin({
+ remarkPlugins: handleExtends(mdxOptions.remarkPlugins, DEFAULT_REMARK_PLUGINS),
+ rehypePlugins: handleExtends(mdxOptions.rehypePlugins),
+ // place these after so the user can't override
jsx: true,
jsxImportSource: 'astro',
// Note: disable `.md` support