@@ -4,6 +4,11 @@ import { Badge } from "@/components/ui/badge";
4
4
import { Spin } from "./icons" ;
5
5
import Image from "next/image" ;
6
6
import { Source } from "@/components/types" ;
7
+ import ReactMarkdown from "react-markdown" ;
8
+ import remarkGfm from "remark-gfm" ;
9
+ import { Prism as SyntaxHighlighter } from "react-syntax-highlighter" ;
10
+ import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism" ;
11
+ import type { Options } from "react-markdown" ;
7
12
8
13
// Define interface for the UIMessage - matching what our useMorphikChat hook returns
9
14
export interface UIMessage {
@@ -76,7 +81,50 @@ export function PreviewMessage({ message }: Pick<MessageProps, "message">) {
76
81
message . role === "user" ? "ml-auto bg-primary text-primary-foreground" : "bg-muted"
77
82
} `}
78
83
>
79
- < div className = "prose prose-sm dark:prose-invert break-words" > { message . content } </ div >
84
+ < div className = "prose prose-sm dark:prose-invert max-w-none break-words" >
85
+ { message . role === "assistant" ? (
86
+ < ReactMarkdown
87
+ remarkPlugins = { [ remarkGfm ] }
88
+ components = {
89
+ {
90
+ code ( props ) {
91
+ const { children, className, node, ...rest } = props ;
92
+ const inline = ! className ?. includes ( "language-" ) ;
93
+ const match = / l a n g u a g e - ( \w + ) / . exec ( className || "" ) ;
94
+
95
+ if ( ! inline && match ) {
96
+ const language = match [ 1 ] ;
97
+ return (
98
+ < div className = "my-4 overflow-hidden rounded-md" >
99
+ < SyntaxHighlighter style = { oneDark } language = { language } PreTag = "div" className = "!my-0" >
100
+ { String ( children ) . replace ( / \n $ / , "" ) }
101
+ </ SyntaxHighlighter >
102
+ </ div >
103
+ ) ;
104
+ } else if ( ! inline ) {
105
+ return (
106
+ < div className = "my-4 overflow-hidden rounded-md" >
107
+ < SyntaxHighlighter style = { oneDark } language = "text" PreTag = "div" className = "!my-0" >
108
+ { String ( children ) . replace ( / \n $ / , "" ) }
109
+ </ SyntaxHighlighter >
110
+ </ div >
111
+ ) ;
112
+ }
113
+ return (
114
+ < code className = "rounded bg-muted px-1.5 py-0.5 font-mono text-sm" { ...rest } >
115
+ { children }
116
+ </ code >
117
+ ) ;
118
+ } ,
119
+ } as Options [ "components" ]
120
+ }
121
+ >
122
+ { message . content }
123
+ </ ReactMarkdown >
124
+ ) : (
125
+ message . content // User messages rendered as plain text within prose-styled div
126
+ ) }
127
+ </ div >
80
128
</ div >
81
129
82
130
{ sources && sources . length > 0 && message . role === "assistant" && (
0 commit comments