Skip to content

Commit 7d20064

Browse files
committed
Refactor CodeBlock component to use prism-react-renderer for syntax highlighting, enhancing code presentation and readability.
1 parent 3b6b9ed commit 7d20064

File tree

1 file changed

+14
-3
lines changed
  • docusaurus/src/components/MikrotikNetworking/CodeBlock

1 file changed

+14
-3
lines changed

docusaurus/src/components/MikrotikNetworking/CodeBlock/index.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Highlight, themes } from "prism-react-renderer";
12
import { useState } from "react";
23

34
interface CodeBlockProps {
@@ -15,9 +16,19 @@ const CodeBlock = ({ code }: CodeBlockProps) => {
1516

1617
return (
1718
<div className="relative group">
18-
<pre className="bg-[#1c1c1c] text-gray-300 p-4 text-sm overflow-x-auto">
19-
<code>{code}</code>
20-
</pre>
19+
<Highlight theme={themes.gruvboxMaterialDark} language="bash" code={code}>
20+
{({ className, style, tokens, getLineProps, getTokenProps }) => (
21+
<pre className={`p-4 overflow-x-auto ${className}`} style={style}>
22+
{tokens.map((line, i) => (
23+
<div key={i} {...getLineProps({ line, key: i })}>
24+
{line.map((token, key) => (
25+
<span key={key} {...getTokenProps({ token, key })} />
26+
))}
27+
</div>
28+
))}
29+
</pre>
30+
)}
31+
</Highlight>
2132
<button
2233
onClick={handleCopy}
2334
className="absolute top-2 right-2 bg-gray-700 hover:bg-gray-600 px-2 py-1 text-xs opacity-0 group-hover:opacity-100 transition-opacity"

0 commit comments

Comments
 (0)