Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MDX] Fix: GFM and Smartypants missing by default #4588

Merged
merged 2 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/weak-emus-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/mdx': patch
---

Fix: Add GFM and Smartypants to MDX by default
11 changes: 9 additions & 2 deletions packages/integrations/mdx/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions packages/integrations/mdx/test/mdx-plugins.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down