@@ -10,7 +10,7 @@ import {
10
10
ThemeIcon ,
11
11
Tooltip ,
12
12
} from "@mantine/core" ;
13
- import { useClipboard } from "@mantine/hooks " ;
13
+ import { Prism } from "@mantine/prism " ;
14
14
import { IconCopy , IconUser } from "@tabler/icons-react" ;
15
15
import { useMemo } from "react" ;
16
16
import ReactMarkdown from "react-markdown" ;
@@ -20,9 +20,9 @@ import "../styles/markdown.scss";
20
20
import { CreatePromptModal } from "./CreatePromptModal" ;
21
21
import { LogoIcon } from "./Logo" ;
22
22
import { ScrollIntoView } from "./ScrollIntoView" ;
23
+ import "../utils/prisma-setup" ;
23
24
24
25
export function MessageItem ( { message } : { message : Message } ) {
25
- const clipboard = useClipboard ( { timeout : 500 } ) ;
26
26
const wordCount = useMemo ( ( ) => {
27
27
var matches = message . content . match ( / [ \w \d \’ \' -\( \) ] + / gi) ;
28
28
return matches ? matches . length : 0 ;
@@ -46,29 +46,21 @@ export function MessageItem({ message }: { message: Message }) {
46
46
table : ( { node, ...props } ) => (
47
47
< Table verticalSpacing = "sm" highlightOnHover { ...props } />
48
48
) ,
49
- code : ( { node, inline, ...props } ) =>
50
- inline ? (
49
+ code : ( { node, inline, className, lang, ...props } ) => {
50
+ const languageMatch = / l a n g u a g e - ( \w + ) / . exec ( className || "" ) ;
51
+ const language = languageMatch ? languageMatch [ 1 ] : undefined ;
52
+
53
+ return inline ? (
51
54
< Code { ...props } />
52
55
) : (
53
56
< Box sx = { { position : "relative" } } >
54
- < Code block { ...props } />
55
- < CopyButton value = { String ( props . children ) } >
56
- { ( { copied, copy } ) => (
57
- < Tooltip
58
- label = { copied ? "Copied" : "Copy" }
59
- position = "left"
60
- >
61
- < ActionIcon
62
- sx = { { position : "absolute" , top : 4 , right : 4 } }
63
- onClick = { copy }
64
- >
65
- < IconCopy opacity = { 0.4 } size = { 20 } />
66
- </ ActionIcon >
67
- </ Tooltip >
68
- ) }
69
- </ CopyButton >
57
+ < Prism
58
+ language = { language as any }
59
+ children = { `${ props . children as string } ` }
60
+ />
70
61
</ Box >
71
- ) ,
62
+ ) ;
63
+ } ,
72
64
} }
73
65
/>
74
66
{ message . role === "assistant" && (
0 commit comments