aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/MDX/CodeBlock
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-02-01 15:15:55 +0100
committerArmand Philippot <git@armandphilippot.com>2022-02-01 15:15:55 +0100
commit1e370817560c905a0a3520e245c317f308b6a5e7 (patch)
treef5a1e2c3b8ddbff2cb4d94eff82830388158e4c9 /src/components/MDX/CodeBlock
parent8f8a3957b5d3b33bafaa0a6afe4187f75d6dd2b7 (diff)
chore: add a new settings to handle prism theme from toolbar
Diffstat (limited to 'src/components/MDX/CodeBlock')
-rw-r--r--src/components/MDX/CodeBlock/CodeBlock.tsx10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/components/MDX/CodeBlock/CodeBlock.tsx b/src/components/MDX/CodeBlock/CodeBlock.tsx
index a822744..45a6176 100644
--- a/src/components/MDX/CodeBlock/CodeBlock.tsx
+++ b/src/components/MDX/CodeBlock/CodeBlock.tsx
@@ -5,6 +5,7 @@ import Prism from 'prismjs';
import { ReactChildren, useEffect } from 'react';
import { useIntl } from 'react-intl';
import '@utils/plugins/prism-color-scheme';
+import { usePrismTheme } from '@utils/providers/prism';
const CodeBlock = ({
className,
@@ -29,6 +30,15 @@ const CodeBlock = ({
translateCopyButton(locale, intl);
}, [intl, locale]);
+ const { setCodeBlocks } = usePrismTheme();
+
+ useEffect(() => {
+ const allPre: NodeListOf<HTMLPreElement> = document.querySelectorAll(
+ 'pre[data-prismjs-color-scheme'
+ );
+ setCodeBlocks(allPre);
+ }, [setCodeBlocks, router.asPath]);
+
return (
<div>
<pre className={classNames.join(' ')}>