@@ -2,6 +2,8 @@ import "./Chat.css";
22
33import VoiceChatIcon from "@mui/icons-material/VoiceChat" ;
44import PersonIcon from "@mui/icons-material/Person" ;
5+ import TerminalIcon from '@mui/icons-material/Terminal' ;
6+ import FileUploadIcon from '@mui/icons-material/FileUpload' ;
57import { MessageDict } from "../App" ;
68
79import remarkGfm from 'remark-gfm' ;
@@ -20,36 +22,53 @@ function Message(props: {
2022 const isMarkdown = ( input : string ) => {
2123 const mdRegex = / \[ .* \] \( .* \) | \* \* .* \* \* | _ _ .* _ _ | \# .* | \! \[ .* \] \( .* \) | ` .* ` | \- .* | \| .* \| / g;
2224 return mdRegex . test ( input ) ;
23- }
25+ } ;
26+
27+ let ICONS = {
28+ "upload" : < FileUploadIcon /> ,
29+ "generator" : < VoiceChatIcon /> ,
30+ "system" : < TerminalIcon /> ,
31+ "user" : < PersonIcon /> ,
32+ } ;
2433
2534 return (
26- < div className = { "message " + ( role == "system" ? "system" : "user" ) } >
35+ < div className = { "message " + role } >
2736 < div className = "avatar-holder" >
2837 < div className = "avatar" >
29- { role == "system" ? < VoiceChatIcon /> : < PersonIcon /> }
38+ { ICONS [ role as keyof typeof ICONS ] }
3039 </ div >
3140 </ div >
3241 < div className = "message-body" >
33- { props . type == "code" && (
34- < div >
35- I generated the following code:
36- < SyntaxHighlighter wrapLongLines = { true } language = "python" >
37- { text }
38- </ SyntaxHighlighter >
39- </ div >
40- ) }
41-
42- { [ "message" , "message_status" ] . indexOf ( props . type ) !== - 1 &&
42+ { props . type == "message" &&
4343 ( props . showLoader ? (
4444 < div >
4545 { text } { props . showLoader ? < div className = "loader" > </ div > : null }
4646 </ div >
4747 ) : (
4848 isMarkdown ( text ) ?
49- < ReactMarkdown
50- children = { text }
51- remarkPlugins = { [ remarkGfm ] }
52- /> :
49+ < ReactMarkdown
50+ children = { text }
51+ remarkPlugins = { [ remarkGfm ] }
52+ components = { {
53+ code ( { node, inline, className, children, style, ...props } ) {
54+ const match = / l a n g u a g e - ( \w + ) / . exec ( className || '' )
55+ return ! inline ? (
56+ < SyntaxHighlighter
57+ { ...props }
58+ children = { String ( children ) . replace ( / \n $ / , '' ) }
59+ wrapLongLines = { true }
60+ language = { match ? match [ 1 ] : "python" }
61+ PreTag = "div"
62+ />
63+ ) : (
64+ < code { ...props } className = { className } >
65+ { children }
66+ </ code >
67+ )
68+ }
69+ } }
70+ />
71+ :
5372 < div className = "cell-output" dangerouslySetInnerHTML = { { __html : text } } > </ div >
5473 ) ) }
5574
0 commit comments