[ci] yarn format
This commit is contained in:
parent
9cdada0bcc
commit
8b6b41eb85
7 changed files with 29 additions and 30 deletions
|
@ -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++];
|
||||
|
|
|
@ -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<string> {
|
||||
return new Promise((resolve) => {
|
||||
|
@ -566,7 +565,11 @@ 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);
|
||||
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 code
|
||||
.replace(/[`$]/g, (match) => {
|
||||
return '\\' + match;
|
||||
}).replace(/{/g, '{');
|
||||
})
|
||||
.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 {
|
||||
|
|
|
@ -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'],
|
||||
},
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue