diff --git a/app/lish/[did]/[publication]/[rkey]/PubCodeBlock.tsx b/app/lish/[did]/[publication]/[rkey]/PubCodeBlock.tsx index 726b1a54..93ce70ef 100644 --- a/app/lish/[did]/[publication]/[rkey]/PubCodeBlock.tsx +++ b/app/lish/[did]/[publication]/[rkey]/PubCodeBlock.tsx @@ -2,7 +2,7 @@ import { PubLeafletBlocksCode } from "lexicons/api"; import { useLayoutEffect, useState } from "react"; -import { codeToHtml } from "shiki"; +import { codeToHtml, bundledLanguagesInfo, bundledThemesInfo } from "shiki"; export function PubCodeBlock({ block, @@ -14,10 +14,10 @@ export function PubCodeBlock({ const [html, setHTML] = useState(prerenderedCode || null); useLayoutEffect(() => { - codeToHtml(block.plaintext, { - lang: block.language || "plaintext", - theme: block.syntaxHighlightingTheme || "github-light", - }).then(setHTML); + const lang = bundledLanguagesInfo.find((l) => l.id === block.language)?.id || "plaintext"; + const theme = bundledThemesInfo.find((t) => t.id === block.syntaxHighlightingTheme)?.id || "github-light"; + + codeToHtml(block.plaintext, { lang, theme }).then(setHTML); }, [block]); return (
; } case PubLeafletBlocksCode.isMain(b.block): { - let html = await codeToHtml(b.block.plaintext, { - lang: b.block.language || "plaintext", - theme: b.block.syntaxHighlightingTheme || "github-light", - }); + let { language, syntaxHighlightingTheme } = b.block; + const lang = + bundledLanguagesInfo.find((l) => l.id === language)?.id || "plaintext"; + const theme = + bundledThemesInfo.find((t) => t.id === syntaxHighlightingTheme)?.id || + "github-light"; + + let html = await codeToHtml(b.block.plaintext, { lang, theme }); return (
l.id === language)?.id || "plaintext"; + let theme = + bundledThemesInfo.find((t) => t.id === syntaxHighlightingTheme)?.id || + "github-light"; + + const html = await codeToHtml(block.block.plaintext, { lang, theme }); codeBlocks.set(indexKey, html); } }