summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/test/mdx-plugins.test.js
diff options
context:
space:
mode:
authorGravatar Ben Holmes <hey@bholmes.dev> 2023-01-03 17:12:47 -0500
committerGravatar GitHub <noreply@github.com> 2023-01-03 17:12:47 -0500
commita9c2920264e36cc5dc05f4adc1912187979edb0d (patch)
tree0a1987beb45f2c9a3670ee6122483bea81839139 /packages/integrations/mdx/test/mdx-plugins.test.js
parent163a9a9d0ef8b08a71033e719ba06ff63cd2df60 (diff)
downloadastro-a9c2920264e36cc5dc05f4adc1912187979edb0d.tar.gz
astro-a9c2920264e36cc5dc05f4adc1912187979edb0d.tar.zst
astro-a9c2920264e36cc5dc05f4adc1912187979edb0d.zip
Markdown and MDX configuration rework (#5684)
* feat: change extendDefaults -> gfm * deps: remove smartypants from md/remark * tests: update markdown plugin tests * fix: borked lockfile * feat: allow all Markdown options in MDX config, with extend * deps: remove smartypants from MDX * chore: remove unused `mode` property * chore: remark rehype types * chore: dead code * fix: order of default config properties * refactor: move md defaults to remark * fix: RemarkRehype type * fix: apply defaults based on MD defaults * chore: update plugin tests * chore: add syntaxHighlight test * refactor: remove drafts from config defaults * docs: new MDX config options * chore: add changeset * edit: test both extends for syntax highlight * refactor: remove MDX config deep merge * docs: update README and changeset * edit: avoid -> disable Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * edit: `drafts` clarification Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * edit: remove "scare quotes" Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * docs: MDX config options redraft * docs: add migration * chore: changeset heading levels * refactor: githubFlavoredMarkdown -> gfm * chore: remove unused imports Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Diffstat (limited to 'packages/integrations/mdx/test/mdx-plugins.test.js')
-rw-r--r--packages/integrations/mdx/test/mdx-plugins.test.js134
1 files changed, 50 insertions, 84 deletions
diff --git a/packages/integrations/mdx/test/mdx-plugins.test.js b/packages/integrations/mdx/test/mdx-plugins.test.js
index a077fde45..f74ded3ea 100644
--- a/packages/integrations/mdx/test/mdx-plugins.test.js
+++ b/packages/integrations/mdx/test/mdx-plugins.test.js
@@ -80,91 +80,57 @@ describe('MDX plugins', () => {
expect(selectTocLink(document)).to.be.null;
});
- it('respects "extendDefaultPlugins" when extending markdown', async () => {
- const fixture = await buildFixture({
- markdown: {
- remarkPlugins: [remarkExamplePlugin],
- rehypePlugins: [rehypeExamplePlugin],
- extendDefaultPlugins: true,
- },
- integrations: [mdx()],
- });
-
- const html = await fixture.readFile(FILE);
- const { document } = parseHTML(html);
-
- expect(selectRemarkExample(document)).to.not.be.null;
- expect(selectRehypeExample(document)).to.not.be.null;
- expect(selectGfmLink(document)).to.not.be.null;
- });
-
- it('extends markdown config with extendPlugins: "markdown"', async () => {
- const fixture = await buildFixture({
- markdown: {
- remarkPlugins: [remarkExamplePlugin],
- rehypePlugins: [rehypeExamplePlugin],
- },
- integrations: [
- mdx({
- extendPlugins: 'markdown',
- remarkPlugins: [remarkToc],
- }),
- ],
- });
-
- const html = await fixture.readFile(FILE);
- const { document } = parseHTML(html);
-
- expect(selectRemarkExample(document)).to.not.be.null;
- expect(selectRehypeExample(document)).to.not.be.null;
- expect(selectTocLink(document)).to.not.be.null;
- });
-
- it('extends default plugins with extendPlugins: "astroDefaults"', async () => {
- const fixture = await buildFixture({
- markdown: {
- // should NOT be applied to MDX
- remarkPlugins: [remarkToc],
- },
- integrations: [
- mdx({
- remarkPlugins: [remarkExamplePlugin],
- rehypePlugins: [rehypeExamplePlugin],
- extendPlugins: 'astroDefaults',
- }),
- ],
- });
-
- const html = await fixture.readFile(FILE);
- const { document } = parseHTML(html);
-
- expect(selectGfmLink(document)).to.not.be.null;
- // remark and rehype plugins still respected
- expect(selectRemarkExample(document)).to.not.be.null;
- expect(selectRehypeExample(document)).to.not.be.null;
- // Does NOT inherit TOC from markdown config
- expect(selectTocLink(document)).to.be.null;
- });
-
- it('does not extend default plugins with extendPlugins: false', async () => {
- const fixture = await buildFixture({
- markdown: {
- remarkPlugins: [remarkExamplePlugin],
- },
- integrations: [
- mdx({
- remarkPlugins: [],
- extendPlugins: false,
- }),
- ],
+ for (const extendMarkdownConfig of [true, false]) {
+ describe(`extendMarkdownConfig = ${extendMarkdownConfig}`, () => {
+ let fixture;
+ before(async () => {
+ fixture = await buildFixture({
+ markdown: {
+ remarkPlugins: [remarkToc],
+ gfm: false,
+ },
+ integrations: [
+ mdx({
+ extendMarkdownConfig,
+ remarkPlugins: [remarkExamplePlugin],
+ rehypePlugins: [rehypeExamplePlugin],
+ }),
+ ],
+ });
+ });
+
+ it('Handles MDX plugins', async () => {
+ const html = await fixture.readFile(FILE);
+ const { document } = parseHTML(html);
+
+ expect(selectRemarkExample(document, 'MDX remark plugins not applied.')).to.not.be.null;
+ expect(selectRehypeExample(document, 'MDX rehype plugins not applied.')).to.not.be.null;
+ });
+
+ it('Handles Markdown plugins', async () => {
+ const html = await fixture.readFile(FILE);
+ const { document } = parseHTML(html);
+
+ expect(
+ selectTocLink(
+ document,
+ '`remarkToc` plugin applied unexpectedly. Should override Markdown config.'
+ )
+ ).to.be.null;
+ });
+
+ it('Handles gfm', async () => {
+ const html = await fixture.readFile(FILE);
+ const { document } = parseHTML(html);
+
+ if (extendMarkdownConfig === true) {
+ expect(selectGfmLink(document), 'Does not respect `markdown.gfm` option.').to.be.null;
+ } else {
+ expect(selectGfmLink(document), 'Respects `markdown.gfm` unexpectedly.').to.not.be.null;
+ }
+ });
});
-
- const html = await fixture.readFile(FILE);
- const { document } = parseHTML(html);
-
- expect(selectGfmLink(document)).to.be.null;
- expect(selectRemarkExample(document)).to.be.null;
- });
+ }
it('supports custom recma plugins', async () => {
const fixture = await buildFixture({