Skip to content

How to enable a different (light) code block theme when the website theme changes? #244

Answered by FjellOverflow
satnaing asked this question in FAQ
Discussion options

You must be logged in to vote

The default syntax-highlighter Shikiji can be configured to have multiple themes in astro.config.ts:

shikiConfig: {
-      theme: "github-dark",
+      experimentalThemes: {
+        dark: "github-dark",
+        light: "github-light",
      },
      wrap: true,
    }

The respective light/dark themed syntax-highlighting is set by adding CSS, for instance in src/styles/base.css:

html[data-theme="dark"] .astro-code,
html[data-theme="dark"] .astro-code span {
  color: var(--shiki-dark) !important;
  background-color: var(--shiki-dark-bg) !important;
  font-style: var(--shiki-dark-font-style) !important;
  font-weight: var(--shiki-dark-font-weight) !important;
  text-decoration: var(--shiki-d…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by satnaing
Comment options

satnaing
Aug 3, 2024
Maintainer Author

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
FAQ
Labels
None yet
2 participants