Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ChatMarkdown.tsx

31 lines826 Bytes

1import { memo } from "react";
2import type { Components } from "react-markdown";
3import ReactMarkdown from "react-markdown";
4import rehypeHighlight from "rehype-highlight";
5import remarkGfm from "remark-gfm";
6​
7interface ChatMarkdownProps {
8 text: string;
9}
10​
11const markdownComponents: Components = {
12 a({ node: _node, ...props }) {
13 return <a {...props} target="_blank" rel="noreferrer" />;
14 },
15};
16​
17function ChatMarkdown({ text }: ChatMarkdownProps) {
18 return (
19 <div className="chat-markdown text-sm leading-relaxed text-foreground/80">
20 <ReactMarkdown
21 remarkPlugins={[remarkGfm]}
22 rehypePlugins={[[rehypeHighlight, { detect: true, ignoreMissing: true }]]}
23 components={markdownComponents}
24 >
25 {text}
26 </ReactMarkdown>
27 </div>
28 );
30​
31export default memo(ChatMarkdown);