This commit is contained in:
Timothy Jaeryang Baek committed 2026-11-07 22:51:09 +09:00
1 parent dfc9832051
commit b5eaa59d0a
7 files changed
+206 -247

No files matched your search

+7 -2
View File
@@ -183,9 +183,14 @@ export function isCodeFile(path: string | null): boolean {
* async, callers are completely unaffected by the change.
*/
export async function highlightCode(code: string, filePath: string): Promise<string> {
const lang = languageForFilePath(filePath) ?? 'text';
return highlightCodeBlock(code, languageForFilePath(filePath) ?? 'text');
}
const { codeToHtml } = await import('shiki');
/** Highlight a Markdown fence, falling back to plain text for unknown language tags. */
export async function highlightCodeBlock(code: string, language: string): Promise<string> {
const { codeToHtml, bundledLanguages } = await import('shiki');
const name = language.trim().toLowerCase();
const lang = Object.hasOwn(bundledLanguages, name) ? name : 'text';
return await codeToHtml(code, {
lang,
themes: {