+ 'import { getHighlighter } from "shiki";\n\nimport { processAST, type SyntaxLine } from "./processAST";\n\nimport type { codeToHast } from "shiki";\n\nexport type DiffAST = DePromise<ReturnType<typeof codeToHast>>;\n\nexport type DiffHighlighter = {\n name: string;\n maxLineToIgnoreSyntax: number;\n setMaxLineToIgnoreSyntax: (v: number) => void;\n ignoreSyntaxHighlightList: (string | RegExp)[];\n setIgnoreSyntaxHighlightList: (v: (string | RegExp)[]) => void;\n getAST: (raw: string, fileName?: string, lang?: string) => DiffAST;\n processAST: (ast: DiffAST) => { syntaxFileObject: Record<number, SyntaxLine>; syntaxFileLineNumber: number };\n hasRegisteredCurrentLang: (lang: string) => boolean;\n getHighlighterEngine: () => DePromise<ReturnType<typeof getHighlighter>> | null;\n};\n\nlet internal: DePromise<ReturnType<typeof getHighlighter>> | null = null;\n\nconst getDefaultHighlighter = async () =>\n await getHighlighter({\n themes: ["github-light", "github-dark"],\n langs: [\n "cpp",\n "java",\n "javascript",\n "css",\n "c#",\n "c",\n "c++",\n "vue",\n "vue-html",\n "astro",\n "bash",\n "make",\n "markdown",\n "makefile",\n "bat",\n "cmake",\n "cmd",\n "csv",\n "docker",\n "dockerfile",\n "go",\n "python",\n "html",\n "jsx",\n "tsx",\n "typescript",\n "sql",\n "xml",\n "sass",\n "ssh-config",\n "kotlin",\n "json",\n "swift",\n "txt",\n "diff",\n ],\n });\n\nconst instance = { name: "shiki" };\n\nlet _maxLineToIgnoreSyntax = 2000;\n\nconst _ignoreSyntaxHighlightList: (string | RegExp)[] = [];\n\nObject.defineProperty(instance, "maxLineToIgnoreSyntax", {\n get: () => _maxLineToIgnoreSyntax,\n});\n\nObject.defineProperty(instance, "setMaxLineToIgnoreSyntax", {\n value: (v: number) => {\n _maxLineToIgnoreSyntax = v;\n },\n});\n\nObject.defineProperty(instance, "ignoreSyntaxHighlightList", {\n get: () => _ignoreSyntaxHighlightList,\n});\n\nObject.defineProperty(instance, "setIgnoreSyntaxHighlightList", {\n value: (v: (string | RegExp)[]) => {\n _ignoreSyntaxHighlightList.length = 0;\n _ignoreSyntaxHighlightList.push(...v);\n },\n});\n\nObject.defineProperty(instance, "getAST", {\n value: (raw: string, fileName?: string, lang?: string) => {\n if (\n fileName &&\n highlighter.ignoreSyntaxHighlightList.some((item) =>\n item instanceof RegExp ? item.test(fileName) : fileName === item\n )\n ) {\n __DEV__ &&\n console.warn(\n `ignore syntax for current file, because the fileName is in the ignoreSyntaxHighlightList: ${fileName}`\n );\n return;\n }\n\n try {\n return internal?.codeToHast(raw, { lang: lang, theme: "github-light", mergeWhitespaces: false });\n } catch (e) {\n if (__DEV__) {\n console.error(e);\n } else {\n console.log((e as Error).message);\n }\n return;\n }\n },\n});\n\nObject.defineProperty(instance, "processAST", {\n value: (ast: DiffAST) => {\n return processAST(ast);\n },\n});\n\nObject.defineProperty(instance, "hasRegisteredCurrentLang", {\n value: (lang: string) => {\n return internal?.getLanguage(lang) !== undefined;\n },\n});\n\nObject.defineProperty(instance, "getHighlighterEngine", {\n value: () => {\n return internal;\n },\n});\n\nconst highlighter: DiffHighlighter = instance as DiffHighlighter;\n\nexport const highlighterReady = new Promise<DiffHighlighter>((r) => {\n if (internal) {\n r(highlighter);\n } else {\n getDefaultHighlighter()\n .then((i) => {\n internal = i;\n })\n .then(() => r(highlighter));\n }\n});\n\nexport { processAST } from "./processAST";\n\nexport const versions = __VERSION__;\n\nexport * from "shiki";\n'
0 commit comments