import { type ComponentProps } from "react"; import Copy from "./CopyMdx"; import { SiJavascript, SiTypescript, SiReact, SiPython, SiGo, SiPhp, SiRuby, SiSwift, SiKotlin, SiHtml5, SiCss3, SiSass, SiPostgresql, SiGraphql, SiYaml, SiToml, SiDocker, SiNginx, SiGit, SiGnubash, SiMarkdown, } from "react-icons/si"; import { FaJava, FaCode } from "react-icons/fa"; import { TbJson } from "react-icons/tb"; type PreProps = ComponentProps<"pre"> & { raw?: string; "data-title"?: string; }; // Component to display an icon based on the programming language const LanguageIcon = ({ lang }: { lang: string }) => { const iconProps = { className: "w-4 h-4" }; const languageToIconMap: Record = { gitignore: , docker: , dockerfile: , nginx: , sql: , graphql: , yaml: , yml: , toml: , json: , md: , markdown: , bash: , sh: , shell: , swift: , kotlin: , kt: , kts: , rb: , ruby: , php: , go: , py: , python: , java: , tsx: , typescript: , ts: , jsx: , js: , javascript: , html: , css: , scss: , sass: , }; return languageToIconMap[lang] || ; }; // Function to extract the language from className function getLanguage(className: string = ""): string { const match = className.match(/language-(\w+)/); return match ? match[1] : "default"; } export default function Pre({ children, raw, ...rest }: PreProps) { const { "data-title": title, className, ...restProps } = rest; const language = getLanguage(className); const hasTitle = !!title; return (
{raw && }
{hasTitle && (
{title}
)}
          {children}
        
); }