diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/CopyButton/styles.module.css b/packages/docusaurus-theme-classic/src/theme/CodeBlock/CopyButton/styles.module.css index f91a3d6aacfd..8333e37d1661 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/CopyButton/styles.module.css +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/CopyButton/styles.module.css @@ -7,7 +7,9 @@ .copyButton { display: flex; - background: inherit; + /* TODO: move to base button styling */ + background: var(--prism-background-color); + color: var(--prism-color); border: 1px solid var(--ifm-color-emphasis-300); border-radius: var(--ifm-global-radius); padding: 0.4rem; diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx index 717ef19ceaaf..7f8ea7642c2a 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx @@ -61,7 +61,7 @@ export default function CodeBlock({ theme={prismTheme} code="" language={'text' as Language}> - {({className, style}) => ( + {({className}) => (
+            )}>
             {children}
           
)} @@ -99,7 +98,7 @@ export default function CodeBlock({ theme={prismTheme} code={code} language={(language ?? 'text') as Language}> - {({className, style, tokens, getLineProps, getTokenProps}) => ( + {({className, tokens, getLineProps, getTokenProps}) => (
{codeBlockTitle && ( -
- {codeBlockTitle} -
+
{codeBlockTitle}
)} -
+
 {
 
 function useContextValue(): ContextValue {
   const {
+    prism,
     colorMode: {defaultMode, disableSwitch, respectPrefersColorScheme},
   } = useThemeConfig();
   const [colorMode, setColorModeState] = useState(
@@ -75,7 +76,23 @@ function useContextValue(): ContextValue {
       'data-theme',
       coerceToColorMode(colorMode),
     );
-  }, [colorMode]);
+
+    // Add Prism's CSS variables
+    const root = window.document.documentElement;
+    const currentPrismTheme =
+      (colorMode === 'dark' ? prism.darkTheme : prism.theme) || prism.theme;
+
+    Object.entries(currentPrismTheme.plain).forEach(
+      // eslint-disable-next-line @typescript-eslint/no-explicit-any
+      ([name, color]: [string, any]) => {
+        const cssVarName = `--prism-${name.replace(
+          /[a-z][A-Z\d]/g,
+          (m) => `${m[0]}-${m[1]!.toLowerCase()}`,
+        )}`;
+        root.style.setProperty(cssVarName, color);
+      },
+    );
+  }, [colorMode, prism.theme, prism.darkTheme]);
 
   useEffect(() => {
     if (disableSwitch) {
diff --git a/packages/docusaurus-theme-common/src/hooks/usePrismTheme.ts b/packages/docusaurus-theme-common/src/hooks/usePrismTheme.ts
index bb8034657baa..b791d3119414 100644
--- a/packages/docusaurus-theme-common/src/hooks/usePrismTheme.ts
+++ b/packages/docusaurus-theme-common/src/hooks/usePrismTheme.ts
@@ -5,7 +5,7 @@
  * LICENSE file in the root directory of this source tree.
  */
 
-import defaultTheme from 'prism-react-renderer/themes/palenight';
+import type {PrismTheme} from 'prism-react-renderer';
 import {useColorMode} from '../contexts/colorMode';
 import {useThemeConfig} from '../utils/useThemeConfig';
 
@@ -13,10 +13,10 @@ import {useThemeConfig} from '../utils/useThemeConfig';
  * Returns a color-mode-dependent Prism theme: whatever the user specified in
  * the config. Falls back to `palenight`.
  */
-export function usePrismTheme(): typeof defaultTheme {
+export function usePrismTheme(): PrismTheme {
   const {prism} = useThemeConfig();
   const {colorMode} = useColorMode();
-  const lightModeTheme = prism.theme || defaultTheme;
+  const lightModeTheme = prism.theme;
   const darkModeTheme = prism.darkTheme || lightModeTheme;
   const prismTheme = colorMode === 'dark' ? darkModeTheme : lightModeTheme;
 
diff --git a/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts b/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts
index 684b573b96cf..9a944c433bbe 100644
--- a/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts
+++ b/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts
@@ -53,7 +53,7 @@ export type AnnouncementBarConfig = {
 };
 
 export type PrismConfig = {
-  theme?: PrismTheme;
+  theme: PrismTheme;
   darkTheme?: PrismTheme;
   defaultLanguage?: string;
   additionalLanguages: string[];