aboutsummaryrefslogtreecommitdiff
path: root/src/Code.tsx
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-10-22 22:51:50 +0300
committereug-vs <eugene@eug-vs.xyz>2022-10-22 22:51:50 +0300
commit0ed6bf41be126e8a4f274de06545dbf4f3f883c2 (patch)
tree879eab5d2faf28f42ed30bc012a90c58229b55b9 /src/Code.tsx
parent31b71bc0dc377b6a3f578188f2d3ee25cfe2e935 (diff)
downloadbenzin-next-0ed6bf41be126e8a4f274de06545dbf4f3f883c2.tar.gz
feat: support syntax highlighting
Diffstat (limited to 'src/Code.tsx')
-rw-r--r--src/Code.tsx23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Code.tsx b/src/Code.tsx
new file mode 100644
index 0000000..d715230
--- /dev/null
+++ b/src/Code.tsx
@@ -0,0 +1,23 @@
+import { FC } from 'react';
+import SyntaxHighlighter from 'react-syntax-highlighter';
+import { gruvboxDark } from 'react-syntax-highlighter/dist/cjs/styles/hljs';
+
+const Code: FC<any> = ({ node, inline, className, children, ...props }) => {
+ const match = /language-(\w+)/.exec(className || '')
+ return !inline && match ? (
+ <SyntaxHighlighter
+ style={gruvboxDark}
+ language={match[1]}
+ PreTag="div"
+ {...props}
+ >
+ {String(children).replace(/\n$/, '')}
+ </SyntaxHighlighter>
+ ) : (
+ <code className={className} {...props}>
+ {children}
+ </code>
+ );
+}
+
+export default Code;