Commit ca8ef93

HPCesia <me@hpcesia.com>
2025-02-06 16:11:32
feat: code block darkmode support
1 parent f5966ee
Changed files (2)
src/styles/markdown.scss
@@ -169,6 +169,25 @@ article {
     @apply rounded-md bg-primary/10 text-primary;
   }
 
+  .astro-code,
+  .astro-code span {
+    &:where([data-theme='light'], [data-theme='light'] *) {
+      color: var(--shiki-light);
+      background-color: var(--shiki-light-bg);
+      font-style: var(--shiki-light-font-style);
+      font-weight: var(--shiki-light-font-weight);
+      text-decoration: var(--shiki-light-text-decoration);
+    }
+
+    &:where([data-theme='dark'], [data-theme='dark'] *) {
+      color: var(--shiki-dark);
+      background-color: var(--shiki-dark-bg);
+      font-style: var(--shiki-dark-font-style);
+      font-weight: var(--shiki-dark-font-weight);
+      text-decoration: var(--shiki-dark-text-decoration);
+    }
+  }
+
   // 引用块样式
   blockquote {
     padding: 0.25rem 0.25rem 0.25rem 0.75rem;
astro.config.mjs
@@ -21,6 +21,13 @@ export default defineConfig({
     pagefind(),
   ],
   markdown: {
+    shikiConfig: {
+      themes: {
+        light: 'one-light',
+        dark: 'one-dark-pro',
+      },
+      defaultColor: false,
+    },
     remarkPlugins: [remarkReadingTime],
     rehypePlugins: [
       rehypeHeadingIds,