| 126 | } |
| 127 | |
| 128 | function formatMessageWithCode(content: string) { |
| 129 | const parts = content.split(/(```[\s\S]*?```)/); |
| 130 | return ( |
| 131 | <div className="space-y-2"> |
| 132 | {parts.map((part, index) => { |
| 133 | if (part.startsWith('```') && part.endsWith('```')) { |
| 134 | const code = part.slice(3, -3); |
| 135 | const language = code.split('\n')[0].trim(); |
| 136 | const codeContent = code.substring(language.length).trim(); |
| 137 | |
| 138 | return ( |
| 139 | <SyntaxHighlighter |
| 140 | key={index} |
| 141 | language={language || 'javascript'} |
| 142 | style={oneDark} |
| 143 | className="rounded-md text-sm" |
| 144 | > |
| 145 | {codeContent} |
| 146 | </SyntaxHighlighter> |
| 147 | ); |
| 148 | } |
| 149 | return ( |
| 150 | <p key={index} className="text-sm">{part}</p> |
| 151 | ); |
| 152 | })} |
| 153 | </div> |
| 154 | ); |
| 155 | } |