import classNames from "classnames"; import copy from "copy-to-clipboard"; import hljs from "highlight.js"; import toast from "react-hot-toast"; import Icon from "../Icon"; import { BaseProps } from "./types"; interface Props extends BaseProps { language: string; content: string; } const CodeBlock: React.FC = ({ language, content }: Props) => { const formatedLanguage = (language || "").toLowerCase() || "text"; let highlightedCode = content; // Users can set Markdown code blocks as `__html` to render HTML directly. if (formatedLanguage === "__html") { return
; } try { const temp = hljs.highlight(content, { language: formatedLanguage, }).value; highlightedCode = temp; } catch (error) { // Skip error and use default highlighted code. } const handleCopyButtonClick = () => { copy(content); toast.success("Copied to clipboard!"); }; return (
{formatedLanguage}
        
      
); }; export default CodeBlock;