Skip to content

Commit ee549e4

Browse files
authored
Merge pull request #25 from devchat-ai/fix216
Add PrismJS for code highlighting
2 parents c5032f5 + 5daaba5 commit ee549e4

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"node-fetch": "^3.3.1",
137137
"nonce": "^1.0.4",
138138
"prism-react-renderer": "^2.3.1",
139+
"prismjs": "^1.29.0",
139140
"quote": "^0.4.0",
140141
"react-i18next": "^13.5.0",
141142
"react-markdown": "^8.0.7",

src/views/components/MessageMarkdown/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Button, Anchor, Stack, Group, Box, createStyles } from "@mantine/core";
22
import React, { useEffect, useMemo, useState } from "react";
33
import ReactMarkdown from "react-markdown";
44
import rehypeRaw from "rehype-raw";
5-
import { Highlight, themes } from "prism-react-renderer";
5+
import { Highlight, themes, Prism } from "prism-react-renderer";
66
import CodeButtons from "./CodeButtons";
77
import Step from "./Step";
88
import LanguageCorner from "./LanguageCorner";
@@ -14,7 +14,10 @@ import { fromMarkdown } from "mdast-util-from-markdown";
1414
import { visit } from "unist-util-visit";
1515
import ChatMark from "@/views/components/ChatMark";
1616
import { useSetState } from "@mantine/hooks";
17-
import { Trans, useTranslation } from "react-i18next";
17+
import { useTranslation } from "react-i18next";
18+
19+
(typeof global !== "undefined" ? global : window).Prism = Prism;
20+
require("prismjs/components/prism-java");
1821

1922
const useStyles = createStyles((theme) => ({
2023
link: {
@@ -228,7 +231,7 @@ Generate a professionally written and formatted release note in markdown with th
228231
"Devchat key is missing from your environment or settings"
229232
)
230233
) {
231-
if(process.env.platform === "vscode") {
234+
if (process.env.platform === "vscode") {
232235
return t("devchat.setkey_vscode");
233236
}
234237
return t("devchat.setkey");
@@ -307,6 +310,7 @@ Generate a professionally written and formatted release note in markdown with th
307310
const match = /language-(\w+)/.exec(className || "");
308311
const value = String(children).replace(/\n$/, "");
309312
let lanugage = match && match[1];
313+
310314
if (!lanugage) {
311315
lanugage = "plaintext";
312316
}

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6892,7 +6892,7 @@ prism-react-renderer@^2.3.1:
68926892
"@types/prismjs" "^1.26.0"
68936893
clsx "^2.0.0"
68946894

6895-
prismjs@^1.27.0:
6895+
prismjs@^1.27.0, prismjs@^1.29.0:
68966896
version "1.29.0"
68976897
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.29.0.tgz#f113555a8fa9b57c35e637bba27509dcf802dd12"
68986898
integrity sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q==

0 commit comments

Comments
 (0)