2
2
import { Box , Paper , Typography , IconButton , Button } from "@mui/material" ;
3
3
import UndoIcon from "@mui/icons-material/Undo" ;
4
4
import { FunctionComponent , PropsWithChildren , useState } from "react" ;
5
- import ReactMarkdown from "react-markdown" ;
6
- import { Prism as SyntaxHighlighter } from "react-syntax-highlighter" ;
7
- import remarkGfm from "remark-gfm" ;
8
- import { vs as highlightStyle } from "react-syntax-highlighter/dist/esm/styles/prism" ;
5
+ import MarkdownContent from "../components/MarkdownContent" ;
9
6
import { ORMessage } from "../pages/HomePage/openRouterTypes" ;
10
7
11
8
type MessageContainerProps = {
@@ -141,23 +138,9 @@ const Message: FunctionComponent<MessageProps> = ({
141
138
message . tool_calls . map ( ( toolCall ) => (
142
139
< Box key = { toolCall . id } sx = { { mb : 1 } } >
143
140
{ toolCall . function . name === "execute_python_code" ? (
144
- < ReactMarkdown
145
- remarkPlugins = { [ remarkGfm ] }
146
- components = { {
147
- code ( { children } ) {
148
- return (
149
- < SyntaxHighlighter
150
- PreTag = "div"
151
- children = { String ( children ) . replace ( / \n $ / , "" ) }
152
- language = "python"
153
- style = { highlightStyle }
154
- />
155
- ) ;
156
- } ,
157
- } }
158
- >
159
- { `\`\`\`python\n${ JSON . parse ( toolCall . function . arguments ) . code } \n\`\`\`` }
160
- </ ReactMarkdown >
141
+ < MarkdownContent
142
+ content = { `\`\`\`python\n${ JSON . parse ( toolCall . function . arguments ) . code } \n\`\`\`` }
143
+ />
161
144
) : (
162
145
< Typography
163
146
variant = "body2"
@@ -200,45 +183,9 @@ const Message: FunctionComponent<MessageProps> = ({
200
183
</ Box >
201
184
{ toolResultExpanded && (
202
185
< Box >
203
- < ReactMarkdown
204
- remarkPlugins = { [ remarkGfm ] }
205
- components = { {
206
- a ( { children, ...props } ) {
207
- return (
208
- < a
209
- href = { props . href }
210
- target = "_blank"
211
- rel = "noopener noreferrer"
212
- { ...props }
213
- >
214
- { children }
215
- </ a >
216
- ) ;
217
- } ,
218
- code ( props ) {
219
- const { children, className, ...rest } = props ;
220
- const match = / l a n g u a g e - ( \w + ) / . exec ( className || "" ) ;
221
- return match ? (
222
- < SyntaxHighlighter
223
- PreTag = "div"
224
- children = { String ( children ) . replace ( / \n $ / , "" ) }
225
- language = { match [ 1 ] }
226
- style = { highlightStyle }
227
- />
228
- ) : (
229
- < code
230
- { ...rest }
231
- className = { className }
232
- style = { { background : "#eee" } }
233
- >
234
- { children }
235
- </ code >
236
- ) ;
237
- } ,
238
- } }
239
- >
240
- { formatMessageContent ( message . content ) }
241
- </ ReactMarkdown >
186
+ < MarkdownContent
187
+ content = { formatMessageContent ( message . content ) }
188
+ />
242
189
</ Box >
243
190
) }
244
191
</ Box >
@@ -247,95 +194,14 @@ const Message: FunctionComponent<MessageProps> = ({
247
194
248
195
// Handle regular text content
249
196
if ( typeof message . content === "string" ) {
250
- return (
251
- < ReactMarkdown
252
- remarkPlugins = { [ remarkGfm ] }
253
- components = { {
254
- a ( { children, ...props } ) {
255
- return (
256
- < a
257
- href = { props . href }
258
- target = "_blank"
259
- rel = "noopener noreferrer"
260
- { ...props }
261
- >
262
- { children }
263
- </ a >
264
- ) ;
265
- } ,
266
- code ( props ) {
267
- const { children, className, ...rest } = props ;
268
- const match = / l a n g u a g e - ( \w + ) / . exec ( className || "" ) ;
269
- return match ? (
270
- < SyntaxHighlighter
271
- PreTag = "div"
272
- children = { String ( children ) . replace ( / \n $ / , "" ) }
273
- language = { match [ 1 ] }
274
- style = { highlightStyle }
275
- />
276
- ) : (
277
- < code
278
- { ...rest }
279
- className = { className }
280
- style = { { background : "#eee" } }
281
- >
282
- { children }
283
- </ code >
284
- ) ;
285
- } ,
286
- } }
287
- >
288
- { message . content }
289
- </ ReactMarkdown >
290
- ) ;
197
+ return < MarkdownContent content = { message . content } /> ;
291
198
}
292
199
293
200
// Handle array of content parts (e.g. text + images)
294
201
if ( Array . isArray ( message . content ) ) {
295
202
return message . content . map ( ( part , index ) => {
296
203
if ( part . type === "text" ) {
297
- return (
298
- < ReactMarkdown
299
- key = { index }
300
- remarkPlugins = { [ remarkGfm ] }
301
- components = { {
302
- a ( { children, ...props } ) {
303
- return (
304
- < a
305
- href = { props . href }
306
- target = "_blank"
307
- rel = "noopener noreferrer"
308
- { ...props }
309
- >
310
- { children }
311
- </ a >
312
- ) ;
313
- } ,
314
- code ( props ) {
315
- const { children, className, ...rest } = props ;
316
- const match = / l a n g u a g e - ( \w + ) / . exec ( className || "" ) ;
317
- return match ? (
318
- < SyntaxHighlighter
319
- PreTag = "div"
320
- children = { String ( children ) . replace ( / \n $ / , "" ) }
321
- language = { match [ 1 ] }
322
- style = { highlightStyle }
323
- />
324
- ) : (
325
- < code
326
- { ...rest }
327
- className = { className }
328
- style = { { background : "#eee" } }
329
- >
330
- { children }
331
- </ code >
332
- ) ;
333
- } ,
334
- } }
335
- >
336
- { part . text }
337
- </ ReactMarkdown >
338
- ) ;
204
+ return < MarkdownContent key = { index } content = { part . text } /> ;
339
205
}
340
206
if ( part . type === "image_url" ) {
341
207
return (
0 commit comments