"use client"; import { CheckIcon, CopyIcon } from "lucide-react"; import type { CSSProperties } from "react"; import { memo, useEffect, useState } from "react"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import { materialDark, materialLight } from "react-syntax-highlighter/dist/esm/styles/prism"; import { Button } from "@/components/ui/button"; import { Skeleton } from "@/components/ui/skeleton"; import { cn, copyToClipboard } from "@/lib/utils"; type MarkdownCodeBlockProps = { className?: string; language: string; codeText: string; isDarkMode: boolean; }; function stripThemeBackgrounds( theme: Record ): Record { const cleaned: Record = {}; for (const key of Object.keys(theme)) { const { background, backgroundColor, ...rest } = theme[key] as CSSProperties & { background?: string; backgroundColor?: string; }; cleaned[key] = rest; } return cleaned; } const cleanMaterialDark = stripThemeBackgrounds(materialDark); const cleanMaterialLight = stripThemeBackgrounds(materialLight); function MarkdownCodeBlockComponent({ className, language, codeText, isDarkMode, }: MarkdownCodeBlockProps) { const [hasCopied, setHasCopied] = useState(false); useEffect(() => { if (!hasCopied) return; const timer = setTimeout(() => setHasCopied(false), 2000); return () => clearTimeout(timer); }, [hasCopied]); return (
{language}
{codeText}
); } export const MarkdownCodeBlock = memo(MarkdownCodeBlockComponent); export function MarkdownCodeBlockSkeleton() { return (
); }