Skip to content

Commit

Permalink
fix: 修复dark模式刷新页面后,Code代码阴影问题 (#226)
Browse files Browse the repository at this point in the history
Co-authored-by: 橙林 <chenglin@dian.so>
  • Loading branch information
BARMPlus and 橙林 authored Mar 6, 2023
1 parent 1a250cc commit b4774e5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/website/components/Markdown/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ 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

const curModeInfo = useMemo(() => {
const mode = theme.includes('dark') ? dark : light
return {
mode,
key: Date.now()
}
}, [theme])

return (
Expand Down Expand Up @@ -54,7 +58,8 @@ export function CodeBlock(props: { children: any; match: any }) {
</div>

<SyntaxHighlighter
style={codeStyle}
key={curModeInfo.key}
style={curModeInfo.mode}
language={props.match?.length ? props.match[1] : undefined}
wrapLines={true}
lineProps={() => {
Expand Down

0 comments on commit b4774e5

Please sign in to comment.