diff --git a/.changeset/weak-emus-confess.md b/.changeset/weak-emus-confess.md new file mode 100644 index 0000000000..4f2b748173 --- /dev/null +++ b/.changeset/weak-emus-confess.md @@ -0,0 +1,5 @@ +--- +'@astrojs/mdx': patch +--- + +Fix: Add GFM and Smartypants to MDX by default diff --git a/packages/integrations/mdx/src/utils.ts b/packages/integrations/mdx/src/utils.ts index 174cad9c11..d4d13ab05e 100644 --- a/packages/integrations/mdx/src/utils.ts +++ b/packages/integrations/mdx/src/utils.ts @@ -127,7 +127,7 @@ export async function getRemarkPlugins( default: remarkPlugins = [ ...remarkPlugins, - ...(config.markdown.extendDefaultPlugins ? DEFAULT_REMARK_PLUGINS : []), + ...(markdownShouldExtendDefaultPlugins(config) ? DEFAULT_REMARK_PLUGINS : []), ...ignoreStringPlugins(config.markdown.remarkPlugins ?? []), ]; break; @@ -162,7 +162,7 @@ export function getRehypePlugins( default: rehypePlugins = [ ...rehypePlugins, - ...(config.markdown.extendDefaultPlugins ? DEFAULT_REHYPE_PLUGINS : []), + ...(markdownShouldExtendDefaultPlugins(config) ? DEFAULT_REHYPE_PLUGINS : []), ...ignoreStringPlugins(config.markdown.rehypePlugins ?? []), ]; break; @@ -172,6 +172,13 @@ export function getRehypePlugins( return rehypePlugins; } +function markdownShouldExtendDefaultPlugins(config: AstroConfig): boolean { + return ( + config.markdown.extendDefaultPlugins || + (config.markdown.remarkPlugins.length === 0 && config.markdown.rehypePlugins.length === 0) + ); +} + function ignoreStringPlugins(plugins: any[]) { let validPlugins: PluggableList = []; let hasInvalidPlugin = false; diff --git a/packages/integrations/mdx/test/mdx-plugins.test.js b/packages/integrations/mdx/test/mdx-plugins.test.js index a5c9480ae5..4cbfaae3ef 100644 --- a/packages/integrations/mdx/test/mdx-plugins.test.js +++ b/packages/integrations/mdx/test/mdx-plugins.test.js @@ -24,6 +24,17 @@ describe('MDX plugins', () => { expect(selectTocLink(document)).to.not.be.null; }); + it('Applies GFM by default', async () => { + const fixture = await buildFixture({ + integrations: [mdx()], + }); + + const html = await fixture.readFile(FILE); + const { document } = parseHTML(html); + + expect(selectGfmLink(document)).to.not.be.null; + }); + it('supports custom rehype plugins', async () => { const fixture = await buildFixture({ integrations: [