Skip to content

Commit 75d33ba

Browse files
authored
Merge pull request #82 from E-mran/Code-Blocks
code blocks update
2 parents 548b4e9 + fd9c568 commit 75d33ba

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/components/chat/chat-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export default function ChatList({
217217
} else {
218218
return (
219219
<pre className="whitespace-pre-wrap" key={index}>
220-
<CodeDisplayBlock code={part} lang="" />
220+
<CodeDisplayBlock code={part} />
221221
</pre>
222222
);
223223
}

src/components/code-display-block.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ import { useTheme } from "next-themes";
88

99
interface ButtonCodeblockProps {
1010
code: string;
11-
lang: string;
1211
}
1312

14-
export default function CodeDisplayBlock({ code, lang }: ButtonCodeblockProps) {
13+
export default function CodeDisplayBlock({ code }: ButtonCodeblockProps) {
1514
const [isCopied, setisCopied] = React.useState(false);
1615
const { theme } = useTheme();
1716

17+
const filteredCode = code.split("\n").slice(1).join("\n") || code;
18+
const language = code.split("\n")[0] || "tsx";
19+
1820
const copyToClipboard = () => {
19-
navigator.clipboard.writeText(code);
21+
navigator.clipboard.writeText(filteredCode);
2022
setisCopied(true);
2123
toast.success("Code copied to clipboard!");
2224
setTimeout(() => {
@@ -45,7 +47,7 @@ export default function CodeDisplayBlock({ code, lang }: ButtonCodeblockProps) {
4547
: { background: "#fcfcfc" }
4648
}
4749
text={code}
48-
language="tsx"
50+
language={language}
4951
showLineNumbers={false}
5052
theme={theme === "dark" ? dracula : github}
5153
/>

0 commit comments

Comments
 (0)