From 0ed6bf41be126e8a4f274de06545dbf4f3f883c2 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 22 Oct 2022 22:51:50 +0300 Subject: feat: support syntax highlighting --- src/Code.tsx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/Code.tsx (limited to 'src/Code.tsx') 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 = ({ node, inline, className, children, ...props }) => { + const match = /language-(\w+)/.exec(className || '') + return !inline && match ? ( + + {String(children).replace(/\n$/, '')} + + ) : ( + + {children} + + ); +} + +export default Code; -- cgit v1.2.3