Skip to content

Commit

Permalink
fix: 暗色模式刷新页面代码块重影问题(盲修,不一定完全修好)#162
Browse files Browse the repository at this point in the history
  • Loading branch information
Mereithhh committed Feb 24, 2023
1 parent 57684a4 commit 8d888c6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/website/components/Markdown/Code.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 (
<>
Expand Down Expand Up @@ -50,7 +54,7 @@ export function CodeBlock(props: { children: any; match: any }) {
</div>

<SyntaxHighlighter
style={theme.includes("dark") ? dark : (light as any)}
style={codeStyle}
language={props.match?.length ? props.match[1] : undefined}
wrapLines={true}
lineProps={() => {
Expand Down

0 comments on commit 8d888c6

Please sign in to comment.