diff options
Diffstat (limited to 'packages/integrations/mdx')
21 files changed, 54 insertions, 54 deletions
diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts index 30f827dc8..de29003ff 100644 --- a/packages/integrations/mdx/src/index.ts +++ b/packages/integrations/mdx/src/index.ts @@ -68,7 +68,7 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI }, contentModuleTypes: await fs.readFile( new URL('../template/content-module-types.d.ts', import.meta.url), - 'utf-8' + 'utf-8', ), // MDX can import scripts and styles, // so wrap all MDX files with script / style propagation checks @@ -91,7 +91,7 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI options: partialMdxOptions, defaults: markdownConfigToMdxOptions( extendMarkdownConfig ? config.markdown : markdownConfigDefaults, - logger + logger, ), }); @@ -113,7 +113,7 @@ const defaultMdxOptions = { function markdownConfigToMdxOptions( markdownConfig: typeof markdownConfigDefaults, - logger: AstroIntegrationLogger + logger: AstroIntegrationLogger, ): MdxOptions { return { ...defaultMdxOptions, diff --git a/packages/integrations/mdx/src/plugins.ts b/packages/integrations/mdx/src/plugins.ts index 3978e5325..082e8f6fd 100644 --- a/packages/integrations/mdx/src/plugins.ts +++ b/packages/integrations/mdx/src/plugins.ts @@ -86,7 +86,7 @@ function getRehypePlugins(mdxOptions: MdxOptions): PluggableList { // Render info from `vfile.data.astro.data.frontmatter` as JS rehypeApplyFrontmatterExport, // Analyze MDX nodes and attach to `vfile.data.__astroMetadata` - rehypeAnalyzeAstroMetadata + rehypeAnalyzeAstroMetadata, ); if (mdxOptions.optimize) { diff --git a/packages/integrations/mdx/src/rehype-apply-frontmatter-export.ts b/packages/integrations/mdx/src/rehype-apply-frontmatter-export.ts index 3a1098800..7fa7f69ef 100644 --- a/packages/integrations/mdx/src/rehype-apply-frontmatter-export.ts +++ b/packages/integrations/mdx/src/rehype-apply-frontmatter-export.ts @@ -10,7 +10,7 @@ export function rehypeApplyFrontmatterExport() { throw new Error( // Copied from Astro core `errors-data` // TODO: find way to import error data from core - '[MDX] A remark or rehype plugin attempted to inject invalid frontmatter. Ensure "astro.frontmatter" is set to a valid JSON object that is not `null` or `undefined`.' + '[MDX] A remark or rehype plugin attempted to inject invalid frontmatter. Ensure "astro.frontmatter" is set to a valid JSON object that is not `null` or `undefined`.', ); const { frontmatter } = astroData; const exportNodes = [ @@ -40,8 +40,8 @@ export function rehypeApplyFrontmatterExport() { 'server:root': true, children, }); - };` - ) + };`, + ), ); } tree.children = exportNodes.concat(tree.children); diff --git a/packages/integrations/mdx/src/rehype-collect-headings.ts b/packages/integrations/mdx/src/rehype-collect-headings.ts index 69e3f9b1b..fafc59721 100644 --- a/packages/integrations/mdx/src/rehype-collect-headings.ts +++ b/packages/integrations/mdx/src/rehype-collect-headings.ts @@ -5,7 +5,7 @@ export function rehypeInjectHeadingsExport() { return function (tree: any, file: MarkdownVFile) { const headings: MarkdownHeading[] = file.data.__astroHeadings || []; tree.children.unshift( - jsToTreeNode(`export function getHeadings() { return ${JSON.stringify(headings)} }`) + jsToTreeNode(`export function getHeadings() { return ${JSON.stringify(headings)} }`), ); }; } diff --git a/packages/integrations/mdx/src/rehype-images-to-component.ts b/packages/integrations/mdx/src/rehype-images-to-component.ts index 6c797fda2..95b500784 100644 --- a/packages/integrations/mdx/src/rehype-images-to-component.ts +++ b/packages/integrations/mdx/src/rehype-images-to-component.ts @@ -157,7 +157,7 @@ export function rehypeImageToComponent() { tree.children.unshift(...importsStatements); tree.children.unshift( - jsToTreeNode(`import { Image as ${ASTRO_IMAGE_IMPORT} } from "astro:assets";`) + jsToTreeNode(`import { Image as ${ASTRO_IMAGE_IMPORT} } from "astro:assets";`), ); // Export `__usesAstroImage` to pick up `astro:assets` usage in the module graph. // @see the '@astrojs/mdx-postprocess' plugin diff --git a/packages/integrations/mdx/src/rehype-optimize-static.ts b/packages/integrations/mdx/src/rehype-optimize-static.ts index ebedb753e..80c28ab9c 100644 --- a/packages/integrations/mdx/src/rehype-optimize-static.ts +++ b/packages/integrations/mdx/src/rehype-optimize-static.ts @@ -183,7 +183,7 @@ interface ElementGroup { function findElementGroups( allPossibleElements: Set<OptimizableNode>, elementMetadatas: WeakMap<OptimizableNode, ElementMetadata>, - isNodeNonStatic: (node: Node) => boolean + isNodeNonStatic: (node: Node) => boolean, ): ElementGroup[] { const elementGroups: ElementGroup[] = []; @@ -195,7 +195,7 @@ function findElementGroups( const metadata = elementMetadatas.get(el); if (!metadata) { throw new Error( - 'Internal MDX error: rehype-optimize-static should have metadata for element node' + 'Internal MDX error: rehype-optimize-static should have metadata for element node', ); } diff --git a/packages/integrations/mdx/src/utils.ts b/packages/integrations/mdx/src/utils.ts index 4705316cc..ad98abb9e 100644 --- a/packages/integrations/mdx/src/utils.ts +++ b/packages/integrations/mdx/src/utils.ts @@ -18,7 +18,7 @@ export interface FileInfo { /** @see 'vite-plugin-utils' for source */ export function getFileInfo(id: string, config: AstroConfig): FileInfo { const sitePathname = appendForwardSlash( - config.site ? new URL(config.base, config.site).pathname : config.base + config.site ? new URL(config.base, config.site).pathname : config.base, ); // Try to grab the file's actual URL @@ -69,7 +69,7 @@ export function jsToTreeNode( acornOpts: AcornOpts = { ecmaVersion: 'latest', sourceType: 'module', - } + }, ): MdxjsEsm { return { type: 'mdxjsEsm', @@ -101,7 +101,7 @@ export function ignoreStringPlugins(plugins: any[], logger: AstroIntegrationLogg } if (hasInvalidPlugin) { logger.warn( - `To inherit Markdown plugins in MDX, please use explicit imports in your config instead of "strings." See Markdown docs: https://docs.astro.build/en/guides/markdown-content/#markdown-plugins` + `To inherit Markdown plugins in MDX, please use explicit imports in your config instead of "strings." See Markdown docs: https://docs.astro.build/en/guides/markdown-content/#markdown-plugins`, ); } return validPlugins; diff --git a/packages/integrations/mdx/src/vite-plugin-mdx-postprocess.ts b/packages/integrations/mdx/src/vite-plugin-mdx-postprocess.ts index 7661c0ecf..e00173fbe 100644 --- a/packages/integrations/mdx/src/vite-plugin-mdx-postprocess.ts +++ b/packages/integrations/mdx/src/vite-plugin-mdx-postprocess.ts @@ -50,7 +50,7 @@ function injectUnderscoreFragmentImport(code: string, imports: readonly ImportSp function injectMetadataExports( code: string, exports: readonly ExportSpecifier[], - fileInfo: FileInfo + fileInfo: FileInfo, ) { if (!exports.some(({ n }) => n === 'url')) { code += `\nexport const url = ${JSON.stringify(fileInfo.fileUrl)};`; @@ -101,7 +101,7 @@ function annotateContentExport( code: string, id: string, ssr: boolean, - imports: readonly ImportSpecifier[] + imports: readonly ImportSpecifier[], ) { // Mark `Content` as MDX component code += `\nContent[Symbol.for('mdx-component')] = true`; @@ -117,7 +117,7 @@ function annotateContentExport( code, imports, astroTagComponentImportRegex, - 'astro/runtime/server/index.js' + 'astro/runtime/server/index.js', ) ) { code += `\nimport { __astro_tag_component__ } from 'astro/runtime/server/index.js';`; @@ -135,7 +135,7 @@ function isSpecifierImported( code: string, imports: readonly ImportSpecifier[], specifierRegex: RegExp, - source: string + source: string, ) { for (const imp of imports) { if (imp.n !== source) continue; diff --git a/packages/integrations/mdx/src/vite-plugin-mdx.ts b/packages/integrations/mdx/src/vite-plugin-mdx.ts index 1b966ecd2..b232d1c83 100644 --- a/packages/integrations/mdx/src/vite-plugin-mdx.ts +++ b/packages/integrations/mdx/src/vite-plugin-mdx.ts @@ -54,7 +54,7 @@ export function vitePluginMdx(mdxOptions: MdxOptions): Plugin { // should be called in between those two lifecycle, so this error should never happen if (!processor) { return this.error( - 'MDX processor is not initialized. This is an internal error. Please file an issue.' + 'MDX processor is not initialized. This is an internal error. Please file an issue.', ); } @@ -86,7 +86,7 @@ function getMdxMeta(vfile: VFile): Record<string, any> { const astroMetadata = getAstroMetadata(vfile); if (!astroMetadata) { throw new Error( - 'Internal MDX error: Astro metadata is not set by rehype-analyze-astro-metadata' + 'Internal MDX error: Astro metadata is not set by rehype-analyze-astro-metadata', ); } return { diff --git a/packages/integrations/mdx/test/invalid-mdx-component.test.js b/packages/integrations/mdx/test/invalid-mdx-component.test.js index 4e68fea64..b8152e89c 100644 --- a/packages/integrations/mdx/test/invalid-mdx-component.test.js +++ b/packages/integrations/mdx/test/invalid-mdx-component.test.js @@ -32,7 +32,7 @@ describe('MDX component with runtime error', () => { assert.ok(error); assert.match( error?.hint, - /This issue often occurs when your MDX component encounters runtime errors/ + /This issue often occurs when your MDX component encounters runtime errors/, ); }); }); diff --git a/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js b/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js index e29efa45b..07197e0e5 100644 --- a/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js +++ b/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js @@ -25,7 +25,7 @@ describe('MDX with Astro Markdown remark-rehype config', () => { assert.equal(document.querySelector('#footnote-label').textContent, 'Catatan kaki'); assert.equal( document.querySelector('.data-footnote-backref').getAttribute('aria-label'), - 'Kembali ke konten' + 'Kembali ke konten', ); }); @@ -54,7 +54,7 @@ describe('MDX with Astro Markdown remark-rehype config', () => { assert.equal(document.querySelector('#footnote-label').textContent, 'Catatan kaki'); assert.equal( document.querySelector('.data-footnote-backref').getAttribute('aria-label'), - 'Kembali ke konten' + 'Kembali ke konten', ); }); @@ -83,7 +83,7 @@ describe('MDX with Astro Markdown remark-rehype config', () => { assert.equal(document.querySelector('#footnote-label').textContent, 'Catatan kaki'); assert.equal( document.querySelector('.data-footnote-backref').getAttribute('aria-label'), - 'Back to reference 1' + 'Back to reference 1', ); }); }); diff --git a/packages/integrations/mdx/test/mdx-frontmatter-injection.test.js b/packages/integrations/mdx/test/mdx-frontmatter-injection.test.js index 90ec45e4e..5c8b69d07 100644 --- a/packages/integrations/mdx/test/mdx-frontmatter-injection.test.js +++ b/packages/integrations/mdx/test/mdx-frontmatter-injection.test.js @@ -25,7 +25,7 @@ describe('MDX frontmatter injection', () => { it('rehype supports custom vfile data - reading time', async () => { const frontmatterByPage = JSON.parse(await fixture.readFile('/glob.json')); const readingTimes = frontmatterByPage.map( - (frontmatter = {}) => frontmatter.injectedReadingTime + (frontmatter = {}) => frontmatter.injectedReadingTime, ); assert.equal(readingTimes.length > 0, true); for (let readingTime of readingTimes) { @@ -39,11 +39,11 @@ describe('MDX frontmatter injection', () => { const descriptions = frontmatterByPage.map((frontmatter = {}) => frontmatter.description); assert.equal( descriptions.includes('Processed by remarkDescription plugin: Page 1 description'), - true + true, ); assert.equal( descriptions.includes('Processed by remarkDescription plugin: Page 2 description'), - true + true, ); }); diff --git a/packages/integrations/mdx/test/mdx-frontmatter.test.js b/packages/integrations/mdx/test/mdx-frontmatter.test.js index 3fcbf28e8..df36a2439 100644 --- a/packages/integrations/mdx/test/mdx-frontmatter.test.js +++ b/packages/integrations/mdx/test/mdx-frontmatter.test.js @@ -50,7 +50,7 @@ describe('MDX frontmatter', () => { const { document } = parseHTML(html); const headingSlugs = [...document.querySelectorAll('[data-headings] > li')].map( - (el) => el.textContent + (el) => el.textContent, ); assert.equal(headingSlugs.length > 0, true); @@ -70,7 +70,7 @@ describe('MDX frontmatter', () => { assert.equal( frontmatterFile?.endsWith('with-headings.mdx'), true, - '"file" prop does not end with correct path or is undefined' + '"file" prop does not end with correct path or is undefined', ); assert.equal(frontmatterUrl, '/with-headings'); assert.equal(file, frontmatterFile); diff --git a/packages/integrations/mdx/test/mdx-get-headings.test.js b/packages/integrations/mdx/test/mdx-get-headings.test.js index 29bb427cc..4de8b0a6e 100644 --- a/packages/integrations/mdx/test/mdx-get-headings.test.js +++ b/packages/integrations/mdx/test/mdx-get-headings.test.js @@ -43,7 +43,7 @@ describe('MDX getHeadings', () => { { depth: 3, slug: 'subsection-1', text: 'Subsection 1' }, { depth: 3, slug: 'subsection-2', text: 'Subsection 2' }, { depth: 2, slug: 'section-2', text: 'Section 2' }, - ]) + ]), ); }); @@ -59,7 +59,7 @@ describe('MDX getHeadings', () => { }, { depth: 2, slug: 'h2title', text: 'h2Title' }, { depth: 3, slug: 'h3title', text: 'h3Title' }, - ]) + ]), ); }); }); @@ -100,7 +100,7 @@ describe('MDX heading IDs can be customized by user plugins', () => { const headingIDs = document.querySelectorAll('h1,h2,h3').map((el) => el.id); assert.equal( JSON.stringify(headingIDs), - JSON.stringify(Array.from({ length: headingIDs.length }, (_, idx) => String(idx))) + JSON.stringify(Array.from({ length: headingIDs.length }, (_, idx) => String(idx))), ); }); @@ -114,7 +114,7 @@ describe('MDX heading IDs can be customized by user plugins', () => { { depth: 3, slug: '2', text: 'Subsection 1' }, { depth: 3, slug: '3', text: 'Subsection 2' }, { depth: 2, slug: '4', text: 'Section 2' }, - ]) + ]), ); }); }); @@ -194,7 +194,7 @@ describe('MDX headings with frontmatter', () => { { depth: 4, slug: 'item-2', text: 'Item 2' }, { depth: 5, slug: 'nested-item-3', text: 'Nested Item 3' }, { depth: 6, slug: 'frontmatterunknown', text: 'frontmatter.unknown' }, - ]) + ]), ); }); }); diff --git a/packages/integrations/mdx/test/mdx-get-static-paths.test.js b/packages/integrations/mdx/test/mdx-get-static-paths.test.js index 845676f8f..96f0dc9a4 100644 --- a/packages/integrations/mdx/test/mdx-get-static-paths.test.js +++ b/packages/integrations/mdx/test/mdx-get-static-paths.test.js @@ -28,7 +28,7 @@ describe('getStaticPaths', () => { assert.equal( $('#file').text().includes('fixtures/mdx-get-static-paths/src/content/1.mdx'), true, - 'file is included' + 'file is included', ); }); }); diff --git a/packages/integrations/mdx/test/mdx-math.test.js b/packages/integrations/mdx/test/mdx-math.test.js index 908a88e11..5352eca68 100644 --- a/packages/integrations/mdx/test/mdx-math.test.js +++ b/packages/integrations/mdx/test/mdx-math.test.js @@ -32,7 +32,7 @@ describe('MDX math', () => { assert.equal( mjxStyle.includes('mjx-container[jax="SVG"]'), true, - 'style should not be html-escaped' + 'style should not be html-escaped', ); }); @@ -66,7 +66,7 @@ describe('MDX math', () => { assert.equal( mjxStyle.includes('mjx-container[jax="CHTML"]'), true, - 'style should not be html-escaped' + 'style should not be html-escaped', ); }); }); diff --git a/packages/integrations/mdx/test/mdx-optimize.test.js b/packages/integrations/mdx/test/mdx-optimize.test.js index f504a49c9..47acfdff8 100644 --- a/packages/integrations/mdx/test/mdx-optimize.test.js +++ b/packages/integrations/mdx/test/mdx-optimize.test.js @@ -21,7 +21,7 @@ describe('MDX optimize', () => { assert.equal(document.querySelector('h1').textContent.includes('MDX page'), true); assert.equal( document.querySelector('p').textContent.includes('I once heard a very inspirational quote:'), - true + true, ); const blockquote = document.querySelector('blockquote.custom-blockquote'); @@ -40,7 +40,7 @@ describe('MDX optimize', () => { assert.equal(document.querySelector('h1').textContent.includes('Astro page'), true); assert.equal( document.querySelector('p').textContent.includes('I once heard a very inspirational quote:'), - true + true, ); const blockquote = document.querySelector('blockquote.custom-blockquote'); diff --git a/packages/integrations/mdx/test/mdx-plugins.test.js b/packages/integrations/mdx/test/mdx-plugins.test.js index 124ec52c1..68ce1e22e 100644 --- a/packages/integrations/mdx/test/mdx-plugins.test.js +++ b/packages/integrations/mdx/test/mdx-plugins.test.js @@ -167,9 +167,9 @@ describe('MDX plugins', () => { assert.equal( selectTocLink( document, - '`remarkToc` plugin applied unexpectedly. Should override Markdown config.' + '`remarkToc` plugin applied unexpectedly. Should override Markdown config.', ), - null + null, ); }); @@ -194,13 +194,13 @@ describe('MDX plugins', () => { assert.equal( quote.textContent.includes('"Smartypants" is -- awesome'), true, - 'Does not respect `markdown.smartypants` option.' + 'Does not respect `markdown.smartypants` option.', ); } else { assert.equal( quote.textContent.includes('“Smartypants” is — awesome'), true, - 'Respects `markdown.smartypants` unexpectedly.' + 'Respects `markdown.smartypants` unexpectedly.', ); } }); diff --git a/packages/integrations/mdx/test/mdx-script-style-raw.test.js b/packages/integrations/mdx/test/mdx-script-style-raw.test.js index 5b276f043..dc4f337bf 100644 --- a/packages/integrations/mdx/test/mdx-script-style-raw.test.js +++ b/packages/integrations/mdx/test/mdx-script-style-raw.test.js @@ -34,14 +34,14 @@ describe('MDX script style raw', () => { assert.equal( scriptContent.includes("console.log('raw script')"), true, - 'script should not be html-escaped' + 'script should not be html-escaped', ); const styleContent = document.getElementById('test-style').innerHTML; assert.equal( styleContent.includes('h1[id="script-style-raw"]'), true, - 'style should not be html-escaped' + 'style should not be html-escaped', ); }); }); @@ -61,14 +61,14 @@ describe('MDX script style raw', () => { assert.equal( scriptContent.includes("console.log('raw script')"), true, - 'script should not be html-escaped' + 'script should not be html-escaped', ); const styleContent = document.getElementById('test-style').innerHTML; assert.equal( styleContent.includes('h1[id="script-style-raw"]'), true, - 'style should not be html-escaped' + 'style should not be html-escaped', ); }); }); diff --git a/packages/integrations/mdx/test/mdx-vite-env-vars.test.js b/packages/integrations/mdx/test/mdx-vite-env-vars.test.js index 4e32d12cb..80a9b1cec 100644 --- a/packages/integrations/mdx/test/mdx-vite-env-vars.test.js +++ b/packages/integrations/mdx/test/mdx-vite-env-vars.test.js @@ -32,7 +32,7 @@ describe('MDX - Vite env vars', () => { document .querySelector('[data-env-site]') ?.innerHTML.includes('https://mdx-is-neat.com/blog/cool-post'), - true + true, ); }); it('Transforms `import.meta.env` in variable exports', async () => { @@ -41,13 +41,13 @@ describe('MDX - Vite env vars', () => { assert.equal( document.querySelector('[data-env-variable-exports]')?.innerHTML.includes('MODE works'), - true + true, ); assert.equal( document .querySelector('[data-env-variable-exports-unknown]') ?.innerHTML.includes('exports: ""'), - true + true, ); }); it('Transforms `import.meta.env` in HTML attributes', async () => { diff --git a/packages/integrations/mdx/test/units/rehype-optimize-static.test.js b/packages/integrations/mdx/test/units/rehype-optimize-static.test.js index 675bc3478..6121975a4 100644 --- a/packages/integrations/mdx/test/units/rehype-optimize-static.test.js +++ b/packages/integrations/mdx/test/units/rehype-optimize-static.test.js @@ -36,7 +36,7 @@ describe('rehype-optimize-static', () => { `\ <_components.h1 {...{ "set:html": "hello" -}} />` +}} />`, ); }); @@ -50,7 +50,7 @@ foo bar jsx, `\ <Fragment set:html="<h1>hello</h1> -<p>foo bar</p>" />` +<p>foo bar</p>" />`, ); }); @@ -66,7 +66,7 @@ This is a <Comp /> jsx, `\ <><Fragment set:html="<h1>hello</h1> -" /><_components.p>{"This is a "}<Comp /></_components.p></>` +" /><_components.p>{"This is a "}<Comp /></_components.p></>`, ); }); @@ -83,7 +83,7 @@ foo <strong>bar</strong> baz `\ <Fragment set:html="<h1>hello</h1> <p>foo <strong>bar</strong> baz</p> -<strong>qux</strong>" />` +<strong>qux</strong>" />`, ); }); }); |