import { Button } from "@/src/components/ui/button"; import { copyTextToClipboard } from "@/src/utils/clipboard"; import { cn } from "@/src/utils/tailwind"; import { Check, Copy } from "lucide-react"; import { type FC, memo, useState } from "react"; import { Highlight, themes } from "prism-react-renderer"; interface Props { language: string; value: string; theme?: string; className?: string; } interface languageMap { [key: string]: string; } export const programmingLanguages: languageMap = { javascript: ".js", python: ".py", java: ".java", c: ".c", cpp: ".cpp", "c++": ".cpp", "c#": ".cs", ruby: ".rb", php: ".php", swift: ".swift", "objective-c": ".m", kotlin: ".kt", typescript: ".ts", go: ".go", perl: ".pl", rust: ".rs", scala: ".scala", haskell: ".hs", lua: ".lua", shell: ".sh", sql: ".sql", html: ".html", css: ".css", // add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component }; const CodeBlock: FC = memo(({ language, value, theme, className }) => { const [isCopied, setIsCopied] = useState(false); const handleCopy = () => { setIsCopied(true); void copyTextToClipboard(value ?? ""); setTimeout(() => setIsCopied(false), 1000); }; return (
{language}
{({ className, style, tokens, getLineProps, getTokenProps }) => (
            {tokens.map((line, i) => (
              
{line.map((token, key) => ( ))}
))}
)}
); }); CodeBlock.displayName = "CodeBlock"; export { CodeBlock };