Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复dark模式刷新页面后,Code代码阴影问题 #226

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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