Skip to content

Commit 4e473c4

Browse files
Merge pull request #68 from OctopBP/feature/code-highlight
Replace `Code` with `Prism`
2 parents 7088bba + 3fcf06d commit 4e473c4

File tree

5 files changed

+1435
-1422
lines changed

5 files changed

+1435
-1422
lines changed

package-lock.json

Lines changed: 116 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
"dependencies": {
2626
"@emotion/react": "^11.10.6",
2727
"@emotion/server": "^11.10.0",
28-
"@mantine/core": "^6.0.1",
29-
"@mantine/hooks": "^6.0.1",
30-
"@mantine/next": "^6.0.1",
31-
"@mantine/notifications": "^6.0.1",
28+
"@mantine/core": "^6.0.17",
29+
"@mantine/hooks": "^6.0.17",
30+
"@mantine/next": "^6.0.17",
31+
"@mantine/notifications": "^6.0.17",
32+
"@mantine/prism": "^6.0.17",
3233
"@tabler/icons-react": "^2.9.0",
3334
"@tanstack/react-location": "^3.7.4",
3435
"@types/node": "18.15.0",
@@ -46,6 +47,8 @@
4647
"next": "13.2.4",
4748
"openai": "^3.2.1",
4849
"openai-ext": "^1.2.6",
50+
"prism-react-renderer": "^1.3.1",
51+
"prismjs": "^1.29.0",
4952
"react": "^18.2.0",
5053
"react-dom": "^18.2.0",
5154
"react-icons": "^4.8.0",

src/components/MessageItem.tsx

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
ThemeIcon,
1111
Tooltip,
1212
} from "@mantine/core";
13-
import { useClipboard } from "@mantine/hooks";
13+
import { Prism } from "@mantine/prism";
1414
import { IconCopy, IconUser } from "@tabler/icons-react";
1515
import { useMemo } from "react";
1616
import ReactMarkdown from "react-markdown";
@@ -20,9 +20,9 @@ import "../styles/markdown.scss";
2020
import { CreatePromptModal } from "./CreatePromptModal";
2121
import { LogoIcon } from "./Logo";
2222
import { ScrollIntoView } from "./ScrollIntoView";
23+
import "../utils/prisma-setup";
2324

2425
export function MessageItem({ message }: { message: Message }) {
25-
const clipboard = useClipboard({ timeout: 500 });
2626
const wordCount = useMemo(() => {
2727
var matches = message.content.match(/[\w\d\’\'-\(\)]+/gi);
2828
return matches ? matches.length : 0;
@@ -46,29 +46,21 @@ export function MessageItem({ message }: { message: Message }) {
4646
table: ({ node, ...props }) => (
4747
<Table verticalSpacing="sm" highlightOnHover {...props} />
4848
),
49-
code: ({ node, inline, ...props }) =>
50-
inline ? (
49+
code: ({ node, inline, className, lang, ...props }) => {
50+
const languageMatch = /language-(\w+)/.exec(className || "");
51+
const language = languageMatch ? languageMatch[1] : undefined;
52+
53+
return inline ? (
5154
<Code {...props} />
5255
) : (
5356
<Box sx={{ position: "relative" }}>
54-
<Code block {...props} />
55-
<CopyButton value={String(props.children)}>
56-
{({ copied, copy }) => (
57-
<Tooltip
58-
label={copied ? "Copied" : "Copy"}
59-
position="left"
60-
>
61-
<ActionIcon
62-
sx={{ position: "absolute", top: 4, right: 4 }}
63-
onClick={copy}
64-
>
65-
<IconCopy opacity={0.4} size={20} />
66-
</ActionIcon>
67-
</Tooltip>
68-
)}
69-
</CopyButton>
57+
<Prism
58+
language={language as any}
59+
children={`${props.children as string}`}
60+
/>
7061
</Box>
71-
),
62+
);
63+
},
7264
}}
7365
/>
7466
{message.role === "assistant" && (

0 commit comments

Comments
 (0)