0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

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

* fix: apply Astro defaults on empty md config

* chore: changeset
This commit is contained in:
Ben Holmes 2022-09-01 12:11:13 -04:00 committed by GitHub
parent ef0ed38339
commit db38f61b2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/mdx': patch
---
Fix: Add GFM and Smartypants to MDX by default

View file

@ -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;

View file

@ -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: [