summaryrefslogtreecommitdiff
path: root/packages/integrations
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations')
-rw-r--r--packages/integrations/mdx/src/index.ts6
-rw-r--r--packages/integrations/mdx/src/utils.ts4
-rw-r--r--packages/integrations/mdx/test/mdx-get-headings.test.js42
-rw-r--r--packages/integrations/mdx/test/mdx-rehype-plugins.test.js14
4 files changed, 35 insertions, 31 deletions
diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts
index f7365b505..139e08515 100644
--- a/packages/integrations/mdx/src/index.ts
+++ b/packages/integrations/mdx/src/index.ts
@@ -1,5 +1,4 @@
-import { nodeTypes, compile as mdxCompile } from '@mdx-js/mdx';
-import { VFile } from 'vfile';
+import { compile as mdxCompile, nodeTypes } from '@mdx-js/mdx';
import mdxPlugin, { Options as MdxRollupPluginOptions } from '@mdx-js/rollup';
import type { AstroIntegration } from 'astro';
import { parse as parseESM } from 'es-module-lexer';
@@ -10,10 +9,11 @@ import type { RemarkMdxFrontmatterOptions } from 'remark-mdx-frontmatter';
import remarkMdxFrontmatter from 'remark-mdx-frontmatter';
import remarkShikiTwoslash from 'remark-shiki-twoslash';
import remarkSmartypants from 'remark-smartypants';
+import { VFile } from 'vfile';
import type { Plugin as VitePlugin } from 'vite';
+import rehypeCollectHeadings from './rehype-collect-headings.js';
import remarkPrism from './remark-prism.js';
import { getFileInfo, getFrontmatter } from './utils.js';
-import rehypeCollectHeadings from './rehype-collect-headings.js';
type WithExtends<T> = T | { extends: T };
diff --git a/packages/integrations/mdx/src/utils.ts b/packages/integrations/mdx/src/utils.ts
index 7b2c4f4ec..b5f7082dc 100644
--- a/packages/integrations/mdx/src/utils.ts
+++ b/packages/integrations/mdx/src/utils.ts
@@ -1,7 +1,7 @@
-import type { AstroConfig, SSRError } from 'astro';
import type { Options as AcornOpts } from 'acorn';
-import type { MdxjsEsm } from 'mdast-util-mdx';
import { parse } from 'acorn';
+import type { AstroConfig, SSRError } from 'astro';
+import type { MdxjsEsm } from 'mdast-util-mdx';
import matter from 'gray-matter';
diff --git a/packages/integrations/mdx/test/mdx-get-headings.test.js b/packages/integrations/mdx/test/mdx-get-headings.test.js
index 247ffedb4..1ac7283dd 100644
--- a/packages/integrations/mdx/test/mdx-get-headings.test.js
+++ b/packages/integrations/mdx/test/mdx-get-headings.test.js
@@ -20,8 +20,8 @@ describe('MDX getHeadings', () => {
const html = await fixture.readFile('/test/index.html');
const { document } = parseHTML(html);
- const h2Ids = document.querySelectorAll('h2').map(el => el?.id);
- const h3Ids = document.querySelectorAll('h3').map(el => el?.id);
+ const h2Ids = document.querySelectorAll('h2').map((el) => el?.id);
+ const h3Ids = document.querySelectorAll('h3').map((el) => el?.id);
expect(document.querySelector('h1').id).to.equal('heading-test');
expect(h2Ids).to.contain('section-1');
expect(h2Ids).to.contain('section-2');
@@ -32,25 +32,29 @@ describe('MDX getHeadings', () => {
it('generates correct getHeadings() export', async () => {
const { headingsByPage } = JSON.parse(await fixture.readFile('/pages.json'));
// TODO: make this a snapshot test :)
- expect(JSON.stringify(headingsByPage['./test.mdx'])).to.equal(JSON.stringify([
- { depth: 1, slug: 'heading-test', text: 'Heading test' },
- { depth: 2, slug: 'section-1', text: 'Section 1' },
- { depth: 3, slug: 'subsection-1', text: 'Subsection 1' },
- { depth: 3, slug: 'subsection-2', text: 'Subsection 2' },
- { depth: 2, slug: 'section-2', text: 'Section 2' }
- ]));
+ expect(JSON.stringify(headingsByPage['./test.mdx'])).to.equal(
+ JSON.stringify([
+ { depth: 1, slug: 'heading-test', text: 'Heading test' },
+ { depth: 2, slug: 'section-1', text: 'Section 1' },
+ { depth: 3, slug: 'subsection-1', text: 'Subsection 1' },
+ { depth: 3, slug: 'subsection-2', text: 'Subsection 2' },
+ { depth: 2, slug: 'section-2', text: 'Section 2' },
+ ])
+ );
});
-
+
it('generates correct getHeadings() export for JSX expressions', async () => {
const { headingsByPage } = JSON.parse(await fixture.readFile('/pages.json'));
- expect(JSON.stringify(headingsByPage['./test-with-jsx-expressions.mdx'])).to.equal(JSON.stringify([
- {
- depth: 1,
- slug: 'heading-test-with-jsx-expressions',
- text: 'Heading test with JSX expressions'
- },
- { depth: 2, slug: 'h2title', text: 'h2Title' },
- { depth: 3, slug: 'h3title', text: 'h3Title' }
- ]));
+ expect(JSON.stringify(headingsByPage['./test-with-jsx-expressions.mdx'])).to.equal(
+ JSON.stringify([
+ {
+ depth: 1,
+ slug: 'heading-test-with-jsx-expressions',
+ text: 'Heading test with JSX expressions',
+ },
+ { depth: 2, slug: 'h2title', text: 'h2Title' },
+ { depth: 3, slug: 'h3title', text: 'h3Title' },
+ ])
+ );
});
});
diff --git a/packages/integrations/mdx/test/mdx-rehype-plugins.test.js b/packages/integrations/mdx/test/mdx-rehype-plugins.test.js
index bb0c6eb63..d8761b9fb 100644
--- a/packages/integrations/mdx/test/mdx-rehype-plugins.test.js
+++ b/packages/integrations/mdx/test/mdx-rehype-plugins.test.js
@@ -9,12 +9,12 @@ import { toString } from 'mdast-util-to-string';
import { loadFixture } from '../../../astro/test/test-utils.js';
export function rehypeReadingTime() {
- return function (tree) {
- const readingTime = getReadingTime(toString(tree))
+ return function (tree) {
+ const readingTime = getReadingTime(toString(tree));
tree.children.unshift(
jsToTreeNode(`export const readingTime = ${JSON.stringify(readingTime)}`)
- )
- };
+ );
+ };
}
const FIXTURE_ROOT = new URL('./fixtures/mdx-rehype-plugins/', import.meta.url);
@@ -37,7 +37,7 @@ describe('MDX rehype plugins', () => {
it('removes default getHeadings', async () => {
const html = await fixture.readFile('/space-ipsum/index.html');
const { document } = parseHTML(html);
-
+
const headings = [...document.querySelectorAll('h1, h2')];
expect(headings.length).to.be.greaterThan(0);
for (const heading of headings) {
@@ -47,7 +47,7 @@ describe('MDX rehype plugins', () => {
it('supports custom rehype plugins - reading time', async () => {
const readingTime = JSON.parse(await fixture.readFile('/reading-time.json'));
-
+
expect(readingTime).to.not.be.null;
expect(readingTime.text).to.match(/^\d+ min read/);
});
@@ -70,7 +70,7 @@ describe('MDX rehype plugins', () => {
it('preserves default getHeadings', async () => {
const html = await fixture.readFile('/space-ipsum/index.html');
const { document } = parseHTML(html);
-
+
const headings = [...document.querySelectorAll('h1, h2')];
expect(headings.length).to.be.greaterThan(0);
for (const heading of headings) {