Skip to content

Commit a5635bd

Browse files
committed
fix import and style
1 parent 3fb9b5d commit a5635bd

File tree

2 files changed

+64
-46
lines changed

2 files changed

+64
-46
lines changed

src/components/Chat.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ export function Chat() {
3333
</BreadcrumbItem>
3434
<BreadcrumbSeparator />
3535
<BreadcrumbItem>
36-
<BreadcrumbPage className="truncate w-96">
37-
{extractTitleFromMessage(title)}
38-
</BreadcrumbPage>
36+
<BreadcrumbPage>{extractTitleFromMessage(title)}</BreadcrumbPage>
3937
</BreadcrumbItem>
4038
</BreadcrumbList>
4139
</Breadcrumb>
@@ -46,7 +44,9 @@ export function Chat() {
4644
<ChatBubble variant="sent">
4745
<ChatBubbleAvatar fallback="User" className="w-14" />
4846
<ChatBubbleMessage variant="sent" className="bg-zinc-700">
49-
<Markdown dark>{question.message}</Markdown>
47+
<Markdown className="text-gray-300">
48+
{question.message}
49+
</Markdown>
5050
</ChatBubbleMessage>
5151
</ChatBubble>
5252
<ChatBubble variant="received">

src/components/Markdown.tsx

+60-42
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import remarkGfm from "remark-gfm";
22
import ReactMarkdown from "react-markdown";
33
import { tv } from "tailwind-variants";
4-
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
5-
import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
6-
import { CopyToClipboard } from 'react-copy-to-clipboard';
7-
import { ClipboardCopy } from 'lucide-react';
4+
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
5+
import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism";
6+
import { CopyToClipboard } from "react-copy-to-clipboard";
7+
import { ClipboardCopy } from "lucide-react";
8+
import { cn } from "@/lib/utils";
89

910
const markdown = tv({
1011
base: "prose max-w-full",
@@ -32,49 +33,41 @@ const customStyle = {
3233
...oneDark,
3334
'pre[class*="language-"]': {
3435
...oneDark['pre[class*="language-"]'],
35-
whiteSpace: 'pre-wrap',
36-
background: '#1a1b26',
37-
padding: '1.5rem',
38-
borderRadius: '0.5rem',
39-
margin: '1.5rem 0',
40-
fontSize: '10px',
41-
width: '80%', // Ensure the block takes full width
42-
position: 'relative',
36+
whiteSpace: "pre-wrap",
37+
background: "#1a1b26",
38+
padding: "1.5rem",
39+
borderRadius: "0.5rem",
40+
margin: "1.5rem 0",
41+
fontSize: "10px",
42+
width: "80%", // Ensure the block takes full width
43+
position: "relative",
4344
},
4445
};
4546

46-
4747
export function Markdown({ children, fontSize, className = "" }: Props) {
4848
return (
4949
<ReactMarkdown
5050
components={{
5151
/* eslint-disable @typescript-eslint/no-explicit-any */
5252
code({ className, children, ...props }: any) {
53-
const match = /language-(\w+)/.exec(className || '');
53+
const match = /language-(\w+)/.exec(className || "");
5454
const inline = !match;
5555
return !inline ? (
56-
<div className="relative group"
57-
style={{
58-
maxWidth: '80%', // Adjust this percentage to reduce the width
59-
marginLeft: '0', // Align the box to the left
60-
paddingLeft: '1rem',
61-
paddingRight: '1rem',
62-
}}
63-
>
56+
<div className="relative group w-full ml-0 px-4">
6457
<SyntaxHighlighter
6558
style={{
6659
...customStyle,
6760
'pre[class*="language-"]': {
6861
...oneDark['pre[class*="language-"]'],
69-
background: '#1a1b26',
70-
fontSize: '10x',
71-
whiteSpace: 'pre-wrap',
72-
padding: '1.5rem',
73-
borderRadius: '0.5rem',
74-
margin: '1.5rem 0',
75-
position: 'relative', // Critical for clipboard positioning
76-
width: '100%', // Ensure full width of parent container
77-
boxSizing: 'border-box', // Prevent padding overflow
62+
background: "#1a1b26",
63+
fontSize: "10x",
64+
whiteSpace: "pre-wrap",
65+
padding: "1.5rem",
66+
borderRadius: "0.5rem",
67+
margin: "1.5rem 0",
68+
position: "relative", // Critical for clipboard positioning
69+
width: "100%", // Ensure full width of parent container
70+
boxSizing: "border-box", // Prevent padding overflow
7871
},
7972
}}
8073
language={match[1]}
@@ -84,9 +77,9 @@ export function Markdown({ children, fontSize, className = "" }: Props) {
8477
wrapLines={true}
8578
{...props}
8679
>
87-
{String(children).replace(/\n$/, '')}
80+
{String(children).replace(/\n$/, "")}
8881
</SyntaxHighlighter>
89-
<CopyToClipboard text={String(children).replace(/\n$/, '')}>
82+
<CopyToClipboard text={String(children).replace(/\n$/, "")}>
9083
<button
9184
className="
9285
absolute top-4 right-8 p-2 rounded-md
@@ -99,13 +92,30 @@ export function Markdown({ children, fontSize, className = "" }: Props) {
9992
</button>
10093
</CopyToClipboard>
10194
</div>
102-
103-
104-
10595
) : (
106-
<code className="px-1.5 py-0.5 rounded-md bg-gray-100 text-gray-800 text-sm" {...props}>
96+
<SyntaxHighlighter
97+
style={{
98+
...customStyle,
99+
'pre[class*="language-"]': {
100+
...oneDark['pre[class*="language-"]'],
101+
fontSize: "10x",
102+
whiteSpace: "pre-wrap",
103+
padding: "1.5rem",
104+
borderRadius: "0.5rem",
105+
margin: "1.5rem 0",
106+
position: "relative", // Critical for clipboard positioning
107+
width: "100%", // Ensure full width of parent container
108+
boxSizing: "border-box", // Prevent padding overflow
109+
},
110+
}}
111+
PreTag="div"
112+
className="rounded-lg overflow-hidden shadow-lg text-sm"
113+
showLineNumbers={false}
114+
wrapLines={true}
115+
{...props}
116+
>
107117
{children}
108-
</code>
118+
</SyntaxHighlighter>
109119
);
110120
},
111121
pre({ children }) {
@@ -115,27 +125,35 @@ export function Markdown({ children, fontSize, className = "" }: Props) {
115125
return <h1 className="text-3xl font-bold mb-6">{children}</h1>;
116126
},
117127
h2({ children }) {
118-
return <h2 className="text-2xl font-semibold mt-8 mb-4">{children}</h2>;
128+
return (
129+
<h2 className="text-2xl font-semibold mt-8 mb-4">{children}</h2>
130+
);
119131
},
120132
h3({ children }) {
121133
return <h3 className="text-xl font-medium mt-6 mb-3">{children}</h3>;
122134
},
123-
p({ children }) {
135+
p({ children }) {
124136
return (
125137
<p className={cn("text-gray-600 leading-relaxed mb-4", className)}>
126138
{children}
127139
</p>
128140
);
129141
},
130142
ul({ children }) {
131-
return <ul className="list-disc list-inside mb-4 space-y-2">{children}</ul>;
143+
return (
144+
<ul className="list-disc list-inside mb-4 space-y-2">{children}</ul>
145+
);
132146
},
133147
li({ children }) {
134148
return <li className="text-gray-600">{children}</li>;
135149
},
136150
a({ children, ...props }) {
137151
return (
138-
<a className="text-blue-600 hover:text-blue-800 underline" target="_blank" {...props}>
152+
<a
153+
className="text-blue-600 hover:text-blue-800 underline"
154+
target="_blank"
155+
{...props}
156+
>
139157
{children}
140158
</a>
141159
);

0 commit comments

Comments
 (0)