diff --git a/src/lib/markdown.ts b/src/lib/markdown.ts index 0f8ebf0..cc0da34 100644 --- a/src/lib/markdown.ts +++ b/src/lib/markdown.ts @@ -4,6 +4,31 @@ import { createHighlighter, type Highlighter } from 'shiki' let highlighter: Highlighter | null = null +const allowed_langs = [ + 'python', + 'javascript', + 'typescript', + 'typst', + 'markdown', + 'json', + 'toml', + 'yaml', + 'bash', + 'c', + 'c++', + 'rust', + 'go', + 'zig', + 'makefile', + 'make', + 'nim', + 'nix', + 'kdl', + 'md', + 'sh', + 'mermaid', +] + /** * Markdown 渲染函数。 * @@ -14,29 +39,7 @@ export async function renderMarkdown(content: string): Promise { highlighter = await createHighlighter({ themes: ['one-light', 'one-dark-pro'], /* 额...要我自己定义需要的所有语言吗 */ - langs: [ - 'python', - 'javascript', - 'typescript', - 'typst', - 'markdown', - 'json', - 'toml', - 'yaml', - 'bash', - 'c', - 'c++', - 'rust', - 'go', - 'zig', - 'makefile', - 'make', - 'nim', - 'nix', - 'kdl', - 'md', - 'sh', - ], + langs: allowed_langs, }) } @@ -45,7 +48,7 @@ export async function renderMarkdown(content: string): Promise { linkify: true, highlight: (code, lang) => { return highlighter!.codeToHtml(code, { - lang: lang || 'text', + lang: allowed_langs.indexOf(lang) != -1 ? lang : 'text', themes: { light: 'one-light', dark: 'one-dark-pro',