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:
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:
|
||||
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;
|
||||
|
|
|
@ -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: [
|
||||
|
|
Loading…
Reference in a new issue