import { useCopy } from "~/hooks/use-copy"; import { highlightLine, type SnippetLanguage, type TokenKind } from "~/lib/snippet-highlight"; import { cn } from "~/utils/cn"; type Props = { title?: string; source: string; language?: SnippetLanguage; className?: string }; const TOKEN_COLOR: Record = { comment: "var(--sh-comment)", string: "var(--sh-string)", keyword: "var(--sh-keyword)", property: "var(--sh-property)", entity: "var(--sh-entity)", sign: "var(--sh-sign)", plain: undefined, }; function Line({ line, language }: { line: string; language?: SnippetLanguage }) { if (!line) return ; if (!language) return {line}; return ( {highlightLine(line, language).map((token, index) => ( // oxlint-disable-next-line react/no-array-index-key -- tokens are static and may repeat {token.text} ))} ); } /** Read-only snippet with a title bar and copy button, highlighted when `language` is set. */ export function CodeBlock({ title, source, language, className }: Props) { const { copied, copy } = useCopy(); return (
{title}
        
          {source.split("\n").map((line, index) => (
            // oxlint-disable-next-line react/no-array-index-key -- lines are static and may repeat
            
          ))}
        
      
); }