[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('{');
|
||||||
}
|
}
|
||||||
return !parser.match('---') && !parser.match('<') && !parser.match('{') && !parser.match('`');
|
return !parser.match('---') && !parser.match('<') && !parser.match('{') && !parser.match('`');
|
||||||
}
|
};
|
||||||
|
|
||||||
while (parser.index < parser.template.length && shouldContinue()) {
|
while (parser.index < parser.template.length && shouldContinue()) {
|
||||||
data += parser.template[parser.index++];
|
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'), '');
|
return !arr || !first ? str : str.replace(new RegExp(`^[ \\t]{0,${first}}`, 'gm'), '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Compile page markup */
|
/** Compile page markup */
|
||||||
async function compileHtml(enterNode: TemplateNode, state: CodegenState, compileOptions: CompileOptions): Promise<string> {
|
async function compileHtml(enterNode: TemplateNode, state: CodegenState, compileOptions: CompileOptions): Promise<string> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
@ -566,9 +565,13 @@ async function compileHtml(enterNode: TemplateNode, state: CodegenState, compile
|
||||||
const md = buffers.markdown;
|
const md = buffers.markdown;
|
||||||
const { markdownOptions = {} } = astroConfig;
|
const { markdownOptions = {} } = astroConfig;
|
||||||
const { $scope: scopedClassName } = state.markers.insideMarkdown as Record<'$scope', any>;
|
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 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.out += ',' + result;
|
||||||
buffers.markdown = '';
|
buffers.markdown = '';
|
||||||
|
@ -579,7 +582,7 @@ async function compileHtml(enterNode: TemplateNode, state: CodegenState, compile
|
||||||
async enter(node: TemplateNode, parent: TemplateNode) {
|
async enter(node: TemplateNode, parent: TemplateNode) {
|
||||||
switch (node.type) {
|
switch (node.type) {
|
||||||
case 'Expression': {
|
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 raw = '';
|
||||||
let nextChildIndex = 0;
|
let nextChildIndex = 0;
|
||||||
for (const chunk of node.codeChunks) {
|
for (const chunk of node.codeChunks) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ export function remarkCodeBlock() {
|
||||||
let currentClassName = data?.hProperties?.class ?? '';
|
let currentClassName = data?.hProperties?.class ?? '';
|
||||||
node.data = node.data || {};
|
node.data = node.data || {};
|
||||||
node.data.hProperties = node.data.hProperties || {};
|
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;
|
return node;
|
||||||
};
|
};
|
||||||
|
@ -22,8 +22,8 @@ export function rehypeCodeBlock() {
|
||||||
return { ...child, value: child.value.replace(/\{/g, '{') };
|
return { ...child, value: child.value.replace(/\{/g, '{') };
|
||||||
}
|
}
|
||||||
return child;
|
return child;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
const visitor = (node: any) => {
|
const visitor = (node: any) => {
|
||||||
if (node.tagName === 'code') {
|
if (node.tagName === 'code') {
|
||||||
escapeCode(node);
|
escapeCode(node);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
|
import syntaxMdxjs from 'micromark-extension-mdxjs';
|
||||||
import syntaxMdxjs from 'micromark-extension-mdxjs'
|
import { fromMarkdown, toMarkdown } from 'mdast-util-mdx';
|
||||||
import {fromMarkdown, toMarkdown} from 'mdast-util-mdx'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the micromark and mdast extensions for MDX.js (JS aware 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}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
export function remarkMdx(this: any, options: any) {
|
export function remarkMdx(this: any, options: any) {
|
||||||
let data = this.data()
|
let data = this.data();
|
||||||
|
|
||||||
add('micromarkExtensions', syntaxMdxjs(options))
|
add('micromarkExtensions', syntaxMdxjs(options));
|
||||||
add('fromMarkdownExtensions', fromMarkdown)
|
add('fromMarkdownExtensions', fromMarkdown);
|
||||||
add('toMarkdownExtensions', toMarkdown)
|
add('toMarkdownExtensions', toMarkdown);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} field
|
* @param {string} field
|
||||||
|
@ -25,7 +24,7 @@ export function remarkMdx(this: any, options: any) {
|
||||||
// Useful when externalizing.
|
// Useful when externalizing.
|
||||||
/* c8 ignore next 2 */
|
/* c8 ignore next 2 */
|
||||||
// @ts-ignore Assume it’s an array.
|
// @ts-ignore Assume it’s an array.
|
||||||
if (data[field]) data[field].push(value)
|
if (data[field]) data[field].push(value);
|
||||||
else data[field] = [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['"]/;
|
const prismImportExp = /import Prism from ['"]astro\/components\/Prism.astro['"]/;
|
||||||
/** escaping code samples that contain template string replacement parts, ${foo} or example. */
|
/** escaping code samples that contain template string replacement parts, ${foo} or example. */
|
||||||
function escape(code: string) {
|
function escape(code: string) {
|
||||||
return code.replace(/[`$]/g, (match) => {
|
return code
|
||||||
return '\\' + match;
|
.replace(/[`$]/g, (match) => {
|
||||||
}).replace(/{/g, '{');
|
return '\\' + match;
|
||||||
|
})
|
||||||
|
.replace(/{/g, '{');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Unescape { characters transformed by Markdown generation */
|
/** Unescape { characters transformed by Markdown generation */
|
||||||
function unescapeCode(code: TemplateNode) {
|
function unescapeCode(code: TemplateNode) {
|
||||||
code.children = code.children?.map(child => {
|
code.children = code.children?.map((child) => {
|
||||||
if (child.type === 'Text') {
|
if (child.type === 'Text') {
|
||||||
return { ...child, raw: child.raw.replace(/&#123;/g, '{') }
|
return { ...child, raw: child.raw.replace(/&#123;/g, '{') };
|
||||||
}
|
}
|
||||||
return child;
|
return child;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
/** default export - Transform prism */
|
/** default export - Transform prism */
|
||||||
export default function (module: Script): Transformer {
|
export default function (module: Script): Transformer {
|
||||||
|
|
|
@ -14,7 +14,7 @@ export interface MarkdownRenderingOptions extends Partial<AstroMarkdownOptions>
|
||||||
$?: {
|
$?: {
|
||||||
scopedClassName: string | null;
|
scopedClassName: string | null;
|
||||||
};
|
};
|
||||||
mode: 'md'|'astro-md';
|
mode: 'md' | 'astro-md';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Internal utility for rendering a full markdown file and extracting Frontmatter data */
|
/** Internal utility for rendering a full markdown file and extracting Frontmatter data */
|
||||||
|
|
|
@ -339,12 +339,7 @@ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackO
|
||||||
},
|
},
|
||||||
packageOptions: {
|
packageOptions: {
|
||||||
knownEntrypoints: ['preact-render-to-string'],
|
knownEntrypoints: ['preact-render-to-string'],
|
||||||
external: [
|
external: ['@vue/server-renderer', 'node-fetch', 'prismjs/components/index.js', 'gray-matter'],
|
||||||
'@vue/server-renderer',
|
|
||||||
'node-fetch',
|
|
||||||
'prismjs/components/index.js',
|
|
||||||
'gray-matter',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue