diff --git a/packages/astro-parser/src/parse/state/text.ts b/packages/astro-parser/src/parse/state/text.ts index bde2ec5e4..020d066fd 100644 --- a/packages/astro-parser/src/parse/state/text.ts +++ b/packages/astro-parser/src/parse/state/text.ts @@ -14,7 +14,7 @@ export default function text(parser: Parser) { return !parser.match('<') && !parser.match('{'); } return !parser.match('---') && !parser.match('<') && !parser.match('{') && !parser.match('`'); - } + }; while (parser.index < parser.template.length && shouldContinue()) { data += parser.template[parser.index++]; diff --git a/packages/astro/src/compiler/codegen/index.ts b/packages/astro/src/compiler/codegen/index.ts index fb6bac9be..8535681ea 100644 --- a/packages/astro/src/compiler/codegen/index.ts +++ b/packages/astro/src/compiler/codegen/index.ts @@ -547,7 +547,6 @@ function dedent(str: string) { return !arr || !first ? str : str.replace(new RegExp(`^[ \\t]{0,${first}}`, 'gm'), ''); } - /** Compile page markup */ async function compileHtml(enterNode: TemplateNode, state: CodegenState, compileOptions: CompileOptions): Promise { return new Promise((resolve) => { @@ -566,9 +565,13 @@ async function compileHtml(enterNode: TemplateNode, state: CodegenState, compile const md = buffers.markdown; const { markdownOptions = {} } = astroConfig; const { $scope: scopedClassName } = state.markers.insideMarkdown as Record<'$scope', any>; - let { content: rendered } = await renderMarkdown(dedent(md), { ...markdownOptions as AstroMarkdownOptions, mode: 'astro-md', $: { scopedClassName: scopedClassName.slice(1, -1) } }); + let { content: rendered } = await renderMarkdown(dedent(md), { + ...(markdownOptions as AstroMarkdownOptions), + mode: 'astro-md', + $: { scopedClassName: scopedClassName.slice(1, -1) }, + }); const ast = parse(rendered); - const result = await compileHtml(ast.html, {...state, markers: {...state.markers, insideMarkdown: false }}, compileOptions); + const result = await compileHtml(ast.html, { ...state, markers: { ...state.markers, insideMarkdown: false } }, compileOptions); buffers.out += ',' + result; buffers.markdown = ''; @@ -579,7 +582,7 @@ async function compileHtml(enterNode: TemplateNode, state: CodegenState, compile async enter(node: TemplateNode, parent: TemplateNode) { switch (node.type) { case 'Expression': { - const children: string[] = await Promise.all((node.children ?? []).map(child => compileHtml(child, state, compileOptions))); + const children: string[] = await Promise.all((node.children ?? []).map((child) => compileHtml(child, state, compileOptions))); let raw = ''; let nextChildIndex = 0; for (const chunk of node.codeChunks) { diff --git a/packages/astro/src/compiler/markdown/codeblock.ts b/packages/astro/src/compiler/markdown/codeblock.ts index 3f7e86951..d784d335c 100644 --- a/packages/astro/src/compiler/markdown/codeblock.ts +++ b/packages/astro/src/compiler/markdown/codeblock.ts @@ -7,7 +7,7 @@ export function remarkCodeBlock() { let currentClassName = data?.hProperties?.class ?? ''; node.data = node.data || {}; node.data.hProperties = node.data.hProperties || {}; - node.data.hProperties = { ...node.data.hProperties, class: `language-${lang} ${currentClassName}`.trim(), lang, meta } + node.data.hProperties = { ...node.data.hProperties, class: `language-${lang} ${currentClassName}`.trim(), lang, meta }; return node; }; @@ -22,8 +22,8 @@ export function rehypeCodeBlock() { return { ...child, value: child.value.replace(/\{/g, '{') }; } return child; - }) - } + }); + }; const visitor = (node: any) => { if (node.tagName === 'code') { escapeCode(node); diff --git a/packages/astro/src/compiler/markdown/remark-mdx-lite.ts b/packages/astro/src/compiler/markdown/remark-mdx-lite.ts index 6ec492211..6075134a7 100644 --- a/packages/astro/src/compiler/markdown/remark-mdx-lite.ts +++ b/packages/astro/src/compiler/markdown/remark-mdx-lite.ts @@ -1,6 +1,5 @@ - -import syntaxMdxjs from 'micromark-extension-mdxjs' -import {fromMarkdown, toMarkdown} from 'mdast-util-mdx' +import syntaxMdxjs from 'micromark-extension-mdxjs'; +import { fromMarkdown, toMarkdown } from 'mdast-util-mdx'; /** * Add the micromark and mdast extensions for MDX.js (JS aware MDX). @@ -10,11 +9,11 @@ import {fromMarkdown, toMarkdown} from 'mdast-util-mdx' * @return {void} */ export function remarkMdx(this: any, options: any) { - let data = this.data() + let data = this.data(); - add('micromarkExtensions', syntaxMdxjs(options)) - add('fromMarkdownExtensions', fromMarkdown) - add('toMarkdownExtensions', toMarkdown) + add('micromarkExtensions', syntaxMdxjs(options)); + add('fromMarkdownExtensions', fromMarkdown); + add('toMarkdownExtensions', toMarkdown); /** * @param {string} field @@ -25,7 +24,7 @@ export function remarkMdx(this: any, options: any) { // Useful when externalizing. /* c8 ignore next 2 */ // @ts-ignore Assume it’s an array. - if (data[field]) data[field].push(value) - else data[field] = [value] + if (data[field]) data[field].push(value); + else data[field] = [value]; } } diff --git a/packages/astro/src/compiler/transform/prism.ts b/packages/astro/src/compiler/transform/prism.ts index 5e89e06b4..5d235377a 100644 --- a/packages/astro/src/compiler/transform/prism.ts +++ b/packages/astro/src/compiler/transform/prism.ts @@ -6,19 +6,21 @@ const PRISM_IMPORT = `import Prism from 'astro/components/Prism.astro';\n`; const prismImportExp = /import Prism from ['"]astro\/components\/Prism.astro['"]/; /** escaping code samples that contain template string replacement parts, ${foo} or example. */ function escape(code: string) { - return code.replace(/[`$]/g, (match) => { - return '\\' + match; - }).replace(/{/g, '{'); + return code + .replace(/[`$]/g, (match) => { + return '\\' + match; + }) + .replace(/{/g, '{'); } /** Unescape { characters transformed by Markdown generation */ function unescapeCode(code: TemplateNode) { - code.children = code.children?.map(child => { + code.children = code.children?.map((child) => { if (child.type === 'Text') { - return { ...child, raw: child.raw.replace(/&#123;/g, '{') } + return { ...child, raw: child.raw.replace(/&#123;/g, '{') }; } return child; - }) + }); } /** default export - Transform prism */ export default function (module: Script): Transformer { diff --git a/packages/astro/src/compiler/utils.ts b/packages/astro/src/compiler/utils.ts index 078b0e7ab..5275a42a7 100644 --- a/packages/astro/src/compiler/utils.ts +++ b/packages/astro/src/compiler/utils.ts @@ -14,7 +14,7 @@ export interface MarkdownRenderingOptions extends Partial $?: { scopedClassName: string | null; }; - mode: 'md'|'astro-md'; + mode: 'md' | 'astro-md'; } /** Internal utility for rendering a full markdown file and extracting Frontmatter data */ diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts index b59642f50..e9ddbeb1b 100644 --- a/packages/astro/src/runtime.ts +++ b/packages/astro/src/runtime.ts @@ -339,12 +339,7 @@ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackO }, packageOptions: { knownEntrypoints: ['preact-render-to-string'], - external: [ - '@vue/server-renderer', - 'node-fetch', - 'prismjs/components/index.js', - 'gray-matter', - ], + external: ['@vue/server-renderer', 'node-fetch', 'prismjs/components/index.js', 'gray-matter'], }, });