[ci] format
This commit is contained in:
parent
3b8a744524
commit
c2968b0542
3 changed files with 23 additions and 25 deletions
|
@ -1,13 +1,13 @@
|
||||||
import type { RemarkMdxFrontmatterOptions } from 'remark-mdx-frontmatter';
|
|
||||||
import type { AstroIntegration } from 'astro';
|
|
||||||
import remarkShikiTwoslash from 'remark-shiki-twoslash';
|
|
||||||
import { nodeTypes } from '@mdx-js/mdx';
|
import { nodeTypes } from '@mdx-js/mdx';
|
||||||
import rehypeRaw from 'rehype-raw';
|
|
||||||
import mdxPlugin, { Options as MdxRollupPluginOptions } from '@mdx-js/rollup';
|
import mdxPlugin, { Options as MdxRollupPluginOptions } from '@mdx-js/rollup';
|
||||||
|
import type { AstroIntegration } from 'astro';
|
||||||
import { parse as parseESM } from 'es-module-lexer';
|
import { parse as parseESM } from 'es-module-lexer';
|
||||||
|
import rehypeRaw from 'rehype-raw';
|
||||||
import remarkFrontmatter from 'remark-frontmatter';
|
import remarkFrontmatter from 'remark-frontmatter';
|
||||||
import remarkGfm from 'remark-gfm';
|
import remarkGfm from 'remark-gfm';
|
||||||
|
import type { RemarkMdxFrontmatterOptions } from 'remark-mdx-frontmatter';
|
||||||
import remarkMdxFrontmatter from 'remark-mdx-frontmatter';
|
import remarkMdxFrontmatter from 'remark-mdx-frontmatter';
|
||||||
|
import remarkShikiTwoslash from 'remark-shiki-twoslash';
|
||||||
import remarkSmartypants from 'remark-smartypants';
|
import remarkSmartypants from 'remark-smartypants';
|
||||||
import remarkPrism from './remark-prism.js';
|
import remarkPrism from './remark-prism.js';
|
||||||
import { getFileInfo } from './utils.js';
|
import { getFileInfo } from './utils.js';
|
||||||
|
@ -27,10 +27,7 @@ type MdxOptions = {
|
||||||
|
|
||||||
const DEFAULT_REMARK_PLUGINS = [remarkGfm, remarkSmartypants];
|
const DEFAULT_REMARK_PLUGINS = [remarkGfm, remarkSmartypants];
|
||||||
|
|
||||||
function handleExtends<T>(
|
function handleExtends<T>(config: WithExtends<T[] | undefined>, defaults: T[] = []): T[] {
|
||||||
config: WithExtends<T[] | undefined>,
|
|
||||||
defaults: T[] = [],
|
|
||||||
): T[] {
|
|
||||||
if (Array.isArray(config)) return config;
|
if (Array.isArray(config)) return config;
|
||||||
|
|
||||||
return [...defaults, ...(config?.extends ?? [])];
|
return [...defaults, ...(config?.extends ?? [])];
|
||||||
|
@ -56,7 +53,7 @@ export default function mdx(mdxOptions: MdxOptions = {}): AstroIntegration {
|
||||||
]);
|
]);
|
||||||
rehypePlugins.push([rehypeRaw, { passThrough: nodeTypes }]);
|
rehypePlugins.push([rehypeRaw, { passThrough: nodeTypes }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.markdown.syntaxHighlight === 'prism') {
|
if (config.markdown.syntaxHighlight === 'prism') {
|
||||||
remarkPlugins.push(remarkPrism);
|
remarkPlugins.push(remarkPrism);
|
||||||
rehypePlugins.push([rehypeRaw, { passThrough: nodeTypes }]);
|
rehypePlugins.push([rehypeRaw, { passThrough: nodeTypes }]);
|
||||||
|
|
|
@ -45,15 +45,16 @@ function runHighlighter(lang: string, code: string) {
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
export default function remarkPrism() {
|
export default function remarkPrism() {
|
||||||
return (tree: any) => visit(tree, 'code', (node: any) => {
|
return (tree: any) =>
|
||||||
let { lang, value } = node;
|
visit(tree, 'code', (node: any) => {
|
||||||
node.type = 'html';
|
let { lang, value } = node;
|
||||||
|
node.type = 'html';
|
||||||
|
|
||||||
let { html, classLanguage } = runHighlighter(lang, value);
|
let { html, classLanguage } = runHighlighter(lang, value);
|
||||||
let classes = [classLanguage];
|
let classes = [classLanguage];
|
||||||
node.value = `<pre class="${classes.join(
|
node.value = `<pre class="${classes.join(
|
||||||
' '
|
' '
|
||||||
)}"><code class="${classLanguage}">${html}</code></pre>`;
|
)}"><code class="${classLanguage}">${html}</code></pre>`;
|
||||||
return node;
|
return node;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,10 @@ describe('MDX syntax highlighting', () => {
|
||||||
integrations: [mdx()],
|
integrations: [mdx()],
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
|
|
||||||
const html = await fixture.readFile('/index.html');
|
const html = await fixture.readFile('/index.html');
|
||||||
const { document } = parseHTML(html);
|
const { document } = parseHTML(html);
|
||||||
|
|
||||||
const shikiCodeBlock = document.querySelector('pre.shiki');
|
const shikiCodeBlock = document.querySelector('pre.shiki');
|
||||||
expect(shikiCodeBlock).to.not.be.null;
|
expect(shikiCodeBlock).to.not.be.null;
|
||||||
});
|
});
|
||||||
|
@ -37,10 +37,10 @@ describe('MDX syntax highlighting', () => {
|
||||||
integrations: [mdx()],
|
integrations: [mdx()],
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
|
|
||||||
const html = await fixture.readFile('/index.html');
|
const html = await fixture.readFile('/index.html');
|
||||||
const { document } = parseHTML(html);
|
const { document } = parseHTML(html);
|
||||||
|
|
||||||
const shikiCodeBlock = document.querySelector('pre.shiki.dracula');
|
const shikiCodeBlock = document.querySelector('pre.shiki.dracula');
|
||||||
expect(shikiCodeBlock).to.not.be.null;
|
expect(shikiCodeBlock).to.not.be.null;
|
||||||
});
|
});
|
||||||
|
@ -56,10 +56,10 @@ describe('MDX syntax highlighting', () => {
|
||||||
integrations: [mdx()],
|
integrations: [mdx()],
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
|
|
||||||
const html = await fixture.readFile('/index.html');
|
const html = await fixture.readFile('/index.html');
|
||||||
const { document } = parseHTML(html);
|
const { document } = parseHTML(html);
|
||||||
|
|
||||||
const prismCodeBlock = document.querySelector('pre.language-astro');
|
const prismCodeBlock = document.querySelector('pre.language-astro');
|
||||||
expect(prismCodeBlock).to.not.be.null;
|
expect(prismCodeBlock).to.not.be.null;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue