diff options
Diffstat (limited to 'frontend')
| -rw-r--r-- | frontend/app/highlight.ts | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/frontend/app/highlight.ts b/frontend/app/highlight.ts index b17a2c9..ccf0683 100644 --- a/frontend/app/highlight.ts +++ b/frontend/app/highlight.ts @@ -7,10 +7,19 @@ export type { BundledLanguage }; // https://shiki.matsu.io/packages/next export async function highlight(code: string, lang: BundledLanguage) { - const out = await codeToHast(code.trimEnd(), { - lang: lang === "swift" ? "text" : lang, - theme: "github-light", - }); + let out; + try { + out = await codeToHast(code.trimEnd(), { + lang, + theme: "github-light", + }); + } catch { + // Fallback to plaintext (no highlight). + out = await codeToHast(code.trimEnd(), { + lang: "text", + theme: "github-light", + }); + } return toJsxRuntime(out, { Fragment, |
