mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00

Update README deployment steps and add deploy:secrets script to package.json update local inference script and README update lockfile reconfigure package scripts for development update test execution pass server tests Update README with revised Bun commands and workspace details remove pnpm package manager designator create bun server
70 lines
1.5 KiB
TypeScript
70 lines
1.5 KiB
TypeScript
import React, { useState, useEffect, useCallback, useMemo } from "react";
|
|
import { buildCodeHighlighter } from "./CodeHighlighter";
|
|
|
|
interface CodeBlockProps {
|
|
language: string;
|
|
code: string;
|
|
onRenderComplete: () => void;
|
|
}
|
|
|
|
const highlighter = buildCodeHighlighter();
|
|
|
|
const CodeBlock: React.FC<CodeBlockProps> = ({
|
|
language,
|
|
code,
|
|
onRenderComplete,
|
|
}) => {
|
|
const [html, setHtml] = useState<string>("");
|
|
const [loading, setLoading] = useState<boolean>(true);
|
|
|
|
const highlightCode = useCallback(async () => {
|
|
try {
|
|
const highlighted = (await highlighter).codeToHtml(code, {
|
|
lang: language,
|
|
theme: "github-dark",
|
|
});
|
|
setHtml(highlighted);
|
|
} catch (error) {
|
|
console.error("Error highlighting code:", error);
|
|
setHtml(`<pre>${code}</pre>`);
|
|
} finally {
|
|
setLoading(false);
|
|
onRenderComplete();
|
|
}
|
|
}, [language, code, onRenderComplete]);
|
|
|
|
useEffect(() => {
|
|
highlightCode();
|
|
}, [highlightCode]);
|
|
|
|
if (loading) {
|
|
return (
|
|
<div
|
|
style={{
|
|
backgroundColor: "#24292e",
|
|
padding: "10px",
|
|
borderRadius: "1.5em",
|
|
}}
|
|
>
|
|
Loading code...
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div
|
|
dangerouslySetInnerHTML={{ __html: html }}
|
|
style={{
|
|
transition: "none",
|
|
padding: 20,
|
|
backgroundColor: "#24292e",
|
|
overflowX: "auto",
|
|
borderRadius: ".37em",
|
|
fontSize: ".75rem",
|
|
}}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default React.memo(CodeBlock);
|