[MDX] Fix: GFM and Smartypants missing by default (#4588)
* fix: apply Astro defaults on empty md config * chore: changeset
This commit is contained in:
parent
ef0ed38339
commit
db38f61b2b
3 changed files with 25 additions and 2 deletions
5
.changeset/weak-emus-confess.md
Normal file
5
.changeset/weak-emus-confess.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/mdx': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix: Add GFM and Smartypants to MDX by default
|
|
@ -127,7 +127,7 @@ export async function getRemarkPlugins(
|
||||||
default:
|
default:
|
||||||
remarkPlugins = [
|
remarkPlugins = [
|
||||||
...remarkPlugins,
|
...remarkPlugins,
|
||||||
...(config.markdown.extendDefaultPlugins ? DEFAULT_REMARK_PLUGINS : []),
|
...(markdownShouldExtendDefaultPlugins(config) ? DEFAULT_REMARK_PLUGINS : []),
|
||||||
...ignoreStringPlugins(config.markdown.remarkPlugins ?? []),
|
...ignoreStringPlugins(config.markdown.remarkPlugins ?? []),
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
|
@ -162,7 +162,7 @@ export function getRehypePlugins(
|
||||||
default:
|
default:
|
||||||
rehypePlugins = [
|
rehypePlugins = [
|
||||||
...rehypePlugins,
|
...rehypePlugins,
|
||||||
...(config.markdown.extendDefaultPlugins ? DEFAULT_REHYPE_PLUGINS : []),
|
...(markdownShouldExtendDefaultPlugins(config) ? DEFAULT_REHYPE_PLUGINS : []),
|
||||||
...ignoreStringPlugins(config.markdown.rehypePlugins ?? []),
|
...ignoreStringPlugins(config.markdown.rehypePlugins ?? []),
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
|
@ -172,6 +172,13 @@ export function getRehypePlugins(
|
||||||
return rehypePlugins;
|
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[]) {
|
function ignoreStringPlugins(plugins: any[]) {
|
||||||
let validPlugins: PluggableList = [];
|
let validPlugins: PluggableList = [];
|
||||||
let hasInvalidPlugin = false;
|
let hasInvalidPlugin = false;
|
||||||
|
|
|
@ -24,6 +24,17 @@ describe('MDX plugins', () => {
|
||||||
expect(selectTocLink(document)).to.not.be.null;
|
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 () => {
|
it('supports custom rehype plugins', async () => {
|
||||||
const fixture = await buildFixture({
|
const fixture = await buildFixture({
|
||||||
integrations: [
|
integrations: [
|
||||||
|
|
Loading…
Reference in a new issue