diff --git a/src/components/Highlight.tsx b/src/components/Highlight.tsx new file mode 100644 index 0000000..98fd118 --- /dev/null +++ b/src/components/Highlight.tsx @@ -0,0 +1,34 @@ +import { Code, useColorModeValue } from "@chakra-ui/react"; +import { Highlight as PrismHighlight, themes } from "prism-react-renderer"; + +interface HighlightProps { + lang: string; + code: string; +} + +export default function Highlight(props: HighlightProps) { + const codeTheme = useColorModeValue(themes.oneLight, themes.oneDark); + + return ( + + {({ style, tokens, getLineProps, getTokenProps }) => ( + + {tokens.map((line, i) => ( +
+ {line.map((token, key) => ( + + ))} +
+ ))} +
+ )} +
+ ); +} diff --git a/src/components/Markdown.tsx b/src/components/Markdown.tsx index 6eb680f..9390f01 100644 --- a/src/components/Markdown.tsx +++ b/src/components/Markdown.tsx @@ -1,6 +1,6 @@ -import { Code, useColorModeValue } from "@chakra-ui/react"; +import { lazy } from "react"; +import { Code } from "@chakra-ui/react"; import ReactMarkdown from "react-markdown"; -import { Highlight, themes } from "prism-react-renderer"; import remarkGfm from "remark-gfm"; import remarkMath from "remark-math"; @@ -11,13 +11,13 @@ import rehypeMathJaxSvg from "rehype-mathjax"; import "github-markdown-css"; import "./Markdown.css"; +const Highlight = lazy(() => import("./Highlight")); + interface MarkdownProps { markdown: string; } export default function Markdown(props: MarkdownProps) { - const codeTheme = useColorModeValue(themes.oneLight, themes.oneDark); - const remarkPlugins = [remarkGfm, emoji, remarkMath]; const rehypePlugins = [rehypeRaw, rehypeMathJaxSvg]; @@ -34,28 +34,7 @@ export default function Markdown(props: MarkdownProps) { const lang = (match || ["", "text"])[1]; const code = String(children).replace(/\n$/, ""); - const codeBlock = ( - - {({ style, tokens, getLineProps, getTokenProps }) => ( - - {tokens.map((line, i) => ( -
- {line.map((token, key) => ( - - ))} -
- ))} -
- )} -
- ); + const codeBlock = ; const codeInline = {children}; return !inline && match ? codeBlock : codeInline; },