SarahXia0405 commited on
Commit
6277dae
·
verified ·
1 Parent(s): a5568ef

Update web/src/components/Message.tsx

Browse files
Files changed (1) hide show
  1. web/src/components/Message.tsx +28 -53
web/src/components/Message.tsx CHANGED
@@ -1,5 +1,8 @@
1
  import React, { useState } from 'react';
2
  import { Button } from './ui/button';
 
 
 
3
  import {
4
  Copy,
5
  ThumbsUp,
@@ -7,7 +10,6 @@ import {
7
  ChevronDown,
8
  ChevronUp,
9
  Check,
10
- Bot,
11
  X
12
  } from 'lucide-react';
13
  import { Badge } from './ui/badge';
@@ -73,46 +75,6 @@ export function Message({
73
  setCopied(true);
74
  toast.success('Message copied to clipboard');
75
  setTimeout(() => setCopied(false), 2000);
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
  };
117
 
118
  const handleFeedbackClick = (type: 'helpful' | 'not-helpful') => {
@@ -138,7 +100,6 @@ export function Message({
138
  setFeedbackText('');
139
  setSelectedTags([]);
140
  // 注意:不重置 feedback,保持点赞/点踩的状态
141
-
142
  };
143
 
144
  const handleTagToggle = (tag: string) => {
@@ -147,7 +108,6 @@ export function Message({
147
  ? prev.filter(t => t !== tag)
148
  : [...prev, tag]
149
  );
150
-
151
  };
152
 
153
  const handleFeedbackSubmit = () => {
@@ -193,7 +153,6 @@ export function Message({
193
  </div>
194
  ) : null}
195
 
196
-
197
  <div
198
  className={`group flex flex-col gap-2 ${isUser && !showSenderInfo ? 'items-end' : 'items-start'}`}
199
  style={{ maxWidth: 'min(770px, calc(100% - 2rem))' }}
@@ -210,7 +169,6 @@ export function Message({
210
  </div>
211
  )}
212
 
213
-
214
  <div
215
  className={`
216
  rounded-2xl px-4 py-3
@@ -220,15 +178,32 @@ export function Message({
220
  }
221
  `}
222
  >
223
- <p className="whitespace-pre-wrap text-base">{message.content}</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  </div>
225
 
226
-
227
-
228
-
229
-
230
-
231
-
232
  {/* Next Question Button for Quiz Mode */}
233
  {!isUser && showNextButton && !nextButtonClicked && chatMode === 'quiz' && onNextQuestion && (
234
  <div className="mt-2">
@@ -394,4 +369,4 @@ export function Message({
394
  )}
395
  </div>
396
  );
397
- }
 
1
  import React, { useState } from 'react';
2
  import { Button } from './ui/button';
3
+ import ReactMarkdown from "react-markdown";
4
+ import remarkGfm from "remark-gfm";
5
+
6
  import {
7
  Copy,
8
  ThumbsUp,
 
10
  ChevronDown,
11
  ChevronUp,
12
  Check,
 
13
  X
14
  } from 'lucide-react';
15
  import { Badge } from './ui/badge';
 
75
  setCopied(true);
76
  toast.success('Message copied to clipboard');
77
  setTimeout(() => setCopied(false), 2000);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  };
79
 
80
  const handleFeedbackClick = (type: 'helpful' | 'not-helpful') => {
 
100
  setFeedbackText('');
101
  setSelectedTags([]);
102
  // 注意:不重置 feedback,保持点赞/点踩的状态
 
103
  };
104
 
105
  const handleTagToggle = (tag: string) => {
 
108
  ? prev.filter(t => t !== tag)
109
  : [...prev, tag]
110
  );
 
111
  };
112
 
113
  const handleFeedbackSubmit = () => {
 
153
  </div>
154
  ) : null}
155
 
 
156
  <div
157
  className={`group flex flex-col gap-2 ${isUser && !showSenderInfo ? 'items-end' : 'items-start'}`}
158
  style={{ maxWidth: 'min(770px, calc(100% - 2rem))' }}
 
169
  </div>
170
  )}
171
 
 
172
  <div
173
  className={`
174
  rounded-2xl px-4 py-3
 
178
  }
179
  `}
180
  >
181
+ {/* Render markdown so **bold** becomes bold (no asterisks shown) */}
182
+ <ReactMarkdown
183
+ remarkPlugins={[remarkGfm]}
184
+ className={[
185
+ "text-base",
186
+ "whitespace-pre-wrap",
187
+ "prose prose-sm max-w-none",
188
+ "prose-p:my-1",
189
+ "prose-ul:my-1 prose-ol:my-1",
190
+ "prose-li:my-0",
191
+ "prose-strong:font-semibold",
192
+ "dark:prose-invert",
193
+ "prose-code:before:content-[''] prose-code:after:content-['']",
194
+ "prose-pre:bg-background/60 prose-pre:border prose-pre:border-border prose-pre:rounded-lg",
195
+ "prose-pre:p-3",
196
+ ].join(" ")}
197
+ components={{
198
+ a: ({ node, ...props }) => (
199
+ <a {...props} target="_blank" rel="noreferrer" />
200
+ ),
201
+ }}
202
+ >
203
+ {message.content}
204
+ </ReactMarkdown>
205
  </div>
206
 
 
 
 
 
 
 
207
  {/* Next Question Button for Quiz Mode */}
208
  {!isUser && showNextButton && !nextButtonClicked && chatMode === 'quiz' && onNextQuestion && (
209
  <div className="mt-2">
 
369
  )}
370
  </div>
371
  );
372
+ }