aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/components/Gaming/CodeBlock.tsx
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-03-08 10:51:41 +0900
committernsfisis <nsfisis@gmail.com>2025-03-08 10:51:41 +0900
commita7ce31249948e4f0c1950de93f3c4f7cdda51cf4 (patch)
treec4c740f0cccd15f825596f7a115f3b8f8eb8ffa7 /frontend/app/components/Gaming/CodeBlock.tsx
parent7f4d16dca85263dcbc7b3bb29f5fc50f4371739d (diff)
parentc06d46eae30c9468535fb6af5e9b822acadbbdb6 (diff)
downloadphperkaigi-2025-albatross-a7ce31249948e4f0c1950de93f3c4f7cdda51cf4.tar.gz
phperkaigi-2025-albatross-a7ce31249948e4f0c1950de93f3c4f7cdda51cf4.tar.zst
phperkaigi-2025-albatross-a7ce31249948e4f0c1950de93f3c4f7cdda51cf4.zip
Merge branch 'phperkaigi-2025'
Diffstat (limited to 'frontend/app/components/Gaming/CodeBlock.tsx')
-rw-r--r--frontend/app/components/Gaming/CodeBlock.tsx31
1 files changed, 24 insertions, 7 deletions
diff --git a/frontend/app/components/Gaming/CodeBlock.tsx b/frontend/app/components/Gaming/CodeBlock.tsx
index b7d45c0..0a9a2e5 100644
--- a/frontend/app/components/Gaming/CodeBlock.tsx
+++ b/frontend/app/components/Gaming/CodeBlock.tsx
@@ -1,8 +1,5 @@
-import Prism, { highlight, languages } from "prismjs";
-import "prismjs/components/prism-swift";
-import "prismjs/themes/prism.min.css";
-
-Prism.manual = true;
+import { useEffect, useState } from "react";
+import { codeToHtml } from "shiki";
type Props = {
code: string;
@@ -10,11 +7,31 @@ type Props = {
};
export default function CodeBlock({ code, language }: Props) {
- const highlighted = highlight(code, languages[language]!, language);
+ const [highlightedCode, setHighlightedCode] = useState<string | null>(null);
+
+ useEffect(() => {
+ let isMounted = true;
+
+ (async () => {
+ const highlighted = await codeToHtml(code, {
+ lang: language,
+ theme: "github-light",
+ });
+ if (isMounted) {
+ setHighlightedCode(highlighted);
+ }
+ })();
+
+ return () => {
+ isMounted = false;
+ };
+ }, [code, language]);
return (
<pre className="h-full w-full p-2 bg-gray-50 rounded-lg border border-gray-300 whitespace-pre-wrap break-words">
- <code dangerouslySetInnerHTML={{ __html: highlighted }} />
+ {highlightedCode === null ? null : (
+ <code dangerouslySetInnerHTML={{ __html: highlightedCode }} />
+ )}
</pre>
);
}