diff --git a/src/components/ChatInterface.jsx b/src/components/ChatInterface.jsx index 0ced685..93c5184 100644 --- a/src/components/ChatInterface.jsx +++ b/src/components/ChatInterface.jsx @@ -21,6 +21,8 @@ import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import remarkMath from 'remark-math'; import rehypeKatex from 'rehype-katex'; +import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; +import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism'; import { useDropzone } from 'react-dropzone'; import TodoList from './TodoList'; import ClaudeLogo from './ClaudeLogo.jsx'; @@ -242,6 +244,8 @@ const markdownComponents = { const looksMultiline = /[\r\n]/.test(raw); const inlineDetected = inline || (node && node.type === 'inlineCode'); const shouldInline = inlineDetected || !looksMultiline; // fallback to inline if single-line + + // Inline code rendering if (shouldInline) { return ( ); } + + // Extract language from className (format: language-xxx) + const match = /language-(\w+)/.exec(className || ''); + const language = match ? match[1] : 'text'; const textToCopy = raw; const handleCopy = () => { @@ -289,8 +297,17 @@ const markdownComponents = { } catch {} }; + // Code block with syntax highlighting return (
+ {/* Language label */} + {language && language !== 'text' && ( +
+ {language} +
+ )} + + {/* Copy button */} -
-          
-            {children}
-          
-        
+ + {/* Syntax highlighted code */} + + {raw} +
); },