Skip to content

Commit 4fc3d40

Browse files
author
smallstone
committed
Add prism-react-renderer for syntax highlighting
1 parent 3e05b0d commit 4fc3d40

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
"ncp": "^2.0.0",
136136
"node-fetch": "^3.3.1",
137137
"nonce": "^1.0.4",
138+
"prism-react-renderer": "^2.3.1",
138139
"quote": "^0.4.0",
139140
"react-i18next": "^13.5.0",
140141
"react-markdown": "^8.0.7",

src/views/components/MessageMarkdown/index.tsx

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { useEffect, useMemo, useState } from "react";
33
import ReactMarkdown from "react-markdown";
44
import rehypeRaw from "rehype-raw";
55
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
6+
import { Highlight, themes } from "prism-react-renderer";
67
import { okaidia } from "react-syntax-highlighter/dist/esm/styles/prism";
78
import CodeButtons from "./CodeButtons";
89
import Step from "./Step";
@@ -352,7 +353,7 @@ Generate a professionally written and formatted release note in markdown with th
352353
>
353354
<LanguageCorner language={lanugage} />
354355
<CodeButtons language={lanugage} code={value} />
355-
<SyntaxHighlighter
356+
{/* <SyntaxHighlighter
356357
{...props}
357358
language={lanugage}
358359
customStyle={{ padding: "35px 10px 10px 10px" }}
@@ -361,7 +362,38 @@ Generate a professionally written and formatted release note in markdown with th
361362
PreTag="div"
362363
>
363364
{value}
364-
</SyntaxHighlighter>
365+
</SyntaxHighlighter> */}
366+
<Highlight
367+
code={value}
368+
theme={themes.okaidia}
369+
language={lanugage}
370+
>
371+
{({
372+
className,
373+
style,
374+
tokens,
375+
getLineProps,
376+
getTokenProps,
377+
}) => (
378+
<pre
379+
className={className}
380+
style={{
381+
...style,
382+
padding: "35px 10px 10px 10px",
383+
...props.style,
384+
}}
385+
{...props}
386+
>
387+
{tokens.map((line, i) => (
388+
<div {...getLineProps({ line, key: i })}>
389+
{line.map((token, key) => (
390+
<span {...getTokenProps({ token, key })} />
391+
))}
392+
</div>
393+
))}
394+
</pre>
395+
)}
396+
</Highlight>
365397
</div>
366398
) : (
367399
<code {...props} className={className}>
@@ -389,10 +421,10 @@ Generate a professionally written and formatted release note in markdown with th
389421
color: "#fff",
390422
},
391423
}}
392-
styles = {{
393-
root:{
424+
styles={{
425+
root: {
394426
marginBottom: 10,
395-
}
427+
},
396428
}}
397429
onClick={() => {
398430
value === "get_devchat_key" && platform === "idea"

yarn.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,6 +2218,11 @@
22182218
resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-6.0.3.tgz#705bb349e789efa06f43f128cef51240753424cb"
22192219
integrity sha512-SuT16Q1K51EAVPz1K29DJ/sXjhSQ0zjvsypYJ6tlwVsRV9jwW5Adq2ch8Dq8kDBCkYnELS7N7VNCSB5nC56t/g==
22202220

2221+
"@types/prismjs@^1.26.0":
2222+
version "1.26.3"
2223+
resolved "https://registry.yarnpkg.com/@types/prismjs/-/prismjs-1.26.3.tgz#47fe8e784c2dee24fe636cab82e090d3da9b7dec"
2224+
integrity sha512-A0D0aTXvjlqJ5ZILMz3rNfDBOx9hHxLZYv2by47Sm/pqW35zzjusrZTryatjN/Rf8Us2gZrJD+KeHbUSTux1Cw==
2225+
22212226
"@types/prop-types@*", "@types/prop-types@^15.0.0":
22222227
version "15.7.11"
22232228
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.11.tgz#2596fb352ee96a1379c657734d4b913a613ad563"
@@ -3256,6 +3261,11 @@ clsx@1.1.1:
32563261
resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.1.1.tgz#98b3134f9abbdf23b2663491ace13c5c03a73188"
32573262
integrity sha512-6/bPho624p3S2pMyvP5kKBPXnI3ufHLObBFCfgx+LkeR5lg2XYy2hqZqUf45ypD8COn2bhgGJSUE+l5dhNBieA==
32583263

3264+
clsx@^2.0.0:
3265+
version "2.1.0"
3266+
resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.0.tgz#e851283bcb5c80ee7608db18487433f7b23f77cb"
3267+
integrity sha512-m3iNNWpd9rl3jvvcBnu70ylMdrXt8Vlq4HYadnU5fwcOtvkSQWPmj7amUcDT2qYI7risszBjI5AUIUox9D16pg==
3268+
32593269
co@^4.6.0:
32603270
version "4.6.0"
32613271
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
@@ -6874,6 +6884,14 @@ prism-react-renderer@^1.2.1:
68746884
resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-1.3.5.tgz#786bb69aa6f73c32ba1ee813fbe17a0115435085"
68756885
integrity sha512-IJ+MSwBWKG+SM3b2SUfdrhC+gu01QkV2KmRQgREThBfSQRoufqRfxfHUxpG1WcaFjP+kojcFyO9Qqtpgt3qLCg==
68766886

6887+
prism-react-renderer@^2.3.1:
6888+
version "2.3.1"
6889+
resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-2.3.1.tgz#e59e5450052ede17488f6bc85de1553f584ff8d5"
6890+
integrity sha512-Rdf+HzBLR7KYjzpJ1rSoxT9ioO85nZngQEoFIhL07XhtJHlCU3SOz0GJ6+qvMyQe0Se+BV3qpe6Yd/NmQF5Juw==
6891+
dependencies:
6892+
"@types/prismjs" "^1.26.0"
6893+
clsx "^2.0.0"
6894+
68776895
prismjs@^1.27.0:
68786896
version "1.29.0"
68796897
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.29.0.tgz#f113555a8fa9b57c35e637bba27509dcf802dd12"

0 commit comments

Comments
 (0)