// Inspired by Chatbot-UI and modified to fit the needs of this project // @see https://github.com/mckaywrigley/chatbot-ui/blob/main/components/Markdown/CodeBlock.tsx 'use client'; import React, { type FC } from 'react'; import { cn } from '@/lib/utils'; import { CopyButton, CopyNpmCommandButton } from './copy-button'; import { ThemedSyntaxHighlighter } from './themed-syntax-highlighter'; const codeCopyButtonClassName = 'absolute top-3 right-2 z-10 size-7 bg-code text-code-foreground opacity-70 hover:bg-muted-foreground/15 hover:text-code-foreground hover:opacity-100 focus-visible:opacity-100'; const codeSurfaceClassName = 'codeblock no-scrollbar max-h-[650px] w-full overflow-auto font-sans'; const codeTagStyle = { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace', fontSize: '0.9rem', textShadow: 'none', }; const lineNumberStyle: React.CSSProperties = { color: 'var(--color-code-number)', userSelect: 'none', }; const codeCustomStyle = { background: 'transparent', margin: 0, padding: '1rem 2.75rem 1rem 1rem', width: '100%', }; const CodeBlock: FC<{ language: string; value: string; className?: string; copyValue?: string; fixedHeight?: boolean; name?: string; npm?: boolean; }> = ({ className, copyValue, fixedHeight, language, npm, value }) => { const code = npm ? `npm install ${value}` : value; const codeCopyValue = copyValue ?? value; const effectiveLanguage = npm ? 'text' : language; const multiline = code.includes('\n'); const showLineNumbers = !npm && multiline; return (