Skip to content

Commit 0864cd2

Browse files
committed
fix: syntax highlighting for std
1 parent 67726aa commit 0864cd2

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

components/CodeBlock.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@ import Prism from "npm:prismjs@1.29.0";
44
export function CodeBlock(
55
{ code, lang }: { code: string; lang: "js" | "ts" | "jsx" | "md" | "bash" },
66
) {
7+
const langMap: Record<string, string> = {
8+
"ts": "typescript",
9+
"js": "javascript",
10+
"jsx": "jsx",
11+
"md": "markdown",
12+
"bash": "bash",
13+
};
14+
15+
const prismLang = langMap[lang] || lang;
16+
const grammar = Prism.languages[prismLang] || Prism.languages.javascript;
17+
718
return (
8-
<pre
9-
class="rounded-lg leading-relaxed bg-slate-800 text-white p-4 sm:p-6 md:p-4 lg:p-6 2xl:p-8 overflow-x-auto"
10-
data-language={lang}
11-
><code dangerouslySetInnerHTML={{ __html: Prism.highlight(code, Prism.languages[lang], lang)}} /></pre>
19+
<div class="gfm-highlight">
20+
<pre
21+
class="rounded-lg leading-relaxed bg-slate-800 text-white p-4 sm:p-6 md:p-4 lg:p-6 2xl:p-8 overflow-x-auto"
22+
data-language={lang}
23+
><code dangerouslySetInnerHTML={{ __html: Prism.highlight(code, grammar, prismLang)}} /></pre>
24+
</div>
1225
);
1326
}

0 commit comments

Comments
 (0)