From 8d888c6cfe72bd45e759c43714f521ec597bf889 Mon Sep 17 00:00:00 2001 From: mereith Date: Fri, 24 Feb 2023 19:14:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9A=97=E8=89=B2=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E9=A1=B5=E9=9D=A2=E4=BB=A3=E7=A0=81=E5=9D=97?= =?UTF-8?q?=E9=87=8D=E5=BD=B1=E9=97=AE=E9=A2=98=EF=BC=88=E7=9B=B2=E4=BF=AE?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E4=B8=80=E5=AE=9A=E5=AE=8C=E5=85=A8=E4=BF=AE?= =?UTF-8?q?=E5=A5=BD=EF=BC=89#162?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/website/components/Markdown/Code.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/website/components/Markdown/Code.tsx b/packages/website/components/Markdown/Code.tsx index a75f36a43..ffb46c4c2 100644 --- a/packages/website/components/Markdown/Code.tsx +++ b/packages/website/components/Markdown/Code.tsx @@ -1,5 +1,5 @@ import dynamic from "next/dynamic"; -import { useContext } from "react"; +import { useContext, useMemo } from "react"; import CopyToClipboard from "react-copy-to-clipboard"; import toast from "react-hot-toast"; import { CodeComponent, CodeProps } from "react-markdown/lib/ast-to-react"; @@ -10,6 +10,10 @@ import { ThemeContext } from "../../utils/themeContext"; export function CodeBlock(props: { children: any; match: any }) { const code = props.children.replace(/\n$/, ""); const { theme } = useContext(ThemeContext); + const codeStyle = useMemo(() => { + if (theme.includes("dark")) { return dark } + return light as any + }, [theme]) return ( <> @@ -50,7 +54,7 @@ export function CodeBlock(props: { children: any; match: any }) { {