[ci] yarn format

This commit is contained in:
natemoo-re 2021-05-21 20:53:47 +00:00 committed by GitHub Actions
parent 9cdada0bcc
commit 8b6b41eb85
7 changed files with 29 additions and 30 deletions

View file

@ -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++];

View file

@ -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) {

View file

@ -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, '&#123;') };
}
return child;
})
}
});
};
const visitor = (node: any) => {
if (node.tagName === 'code') {
escapeCode(node);

View file

@ -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 its an array.
if (data[field]) data[field].push(value)
else data[field] = [value]
if (data[field]) data[field].push(value);
else data[field] = [value];
}
}

View file

@ -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(/&#123;/g, '{');
})
.replace(/&#123;/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(/&#x26;#123;/g, '{') }
return { ...child, raw: child.raw.replace(/&#x26;#123;/g, '{') };
}
return child;
})
});
}
/** default export - Transform prism */
export default function (module: Script): Transformer {

View file

@ -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'],
},
});