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

Missing explanation about "themes" from ShikiConfig in syntax highlighting #8152

Closed
gxlpes opened this issue May 2, 2024 · 2 comments
Closed
Labels
bug Something on the site isn't working

Comments

@gxlpes
Copy link

gxlpes commented May 2, 2024

📝 Issue Description

When trying to set a dual theme, one for light mode and another one for dark mode, the themes config can have two themes.

   shikiConfig: {
      themes: {
        light: 'github-light',
        dark: 'github-dark',
      },

How the themeing is detected? Via prefers-color-scheme?

📋 On which page(s) it occurs

https://docs.astro.build/en/guides/markdown-content/#shiki-configuration

🤔 Expected Behavior

I expected to use a dual themed syntax highlighting with Shiki using the themes object prop that is present in the docs.

👀 Current Behavior

The prop themes is not properly explained in the shikiConfig docs.

🖥️ Browser

Chrome 124.0.6367.91

📄 Additional Information

No response

@gxlpes gxlpes added the bug Something on the site isn't working label May 2, 2024
@gxlpes gxlpes changed the title Missing attribute "themes" from ShikiConfig in syntax highlighting Missing explaination about "themes" from ShikiConfig in syntax highlighting May 2, 2024
@gxlpes gxlpes changed the title Missing explaination about "themes" from ShikiConfig in syntax highlighting Missing explanation about "themes" from ShikiConfig in syntax highlighting May 2, 2024
@gxlpes
Copy link
Author

gxlpes commented May 3, 2024

I found what is wrong.

In the Shiki docs, these are recommended, using the .shiki classname.

@media (prefers-color-scheme: dark) {
  .shiki,
  .shiki span {
    color: var(--shiki-dark) !important;
    background-color: var(--shiki-dark-bg) !important;
    /* Optional, if you also want font styles */
    font-style: var(--shiki-dark-font-style) !important;
    font-weight: var(--shiki-dark-font-weight) !important;
    text-decoration: var(--shiki-dark-text-decoration) !important;
  }
}
html.dark .shiki,
html.dark .shiki span {
  color: var(--shiki-dark) !important;
  background-color: var(--shiki-dark-bg) !important;
  /* Optional, if you also want font styles */
  font-style: var(--shiki-dark-font-style) !important;
  font-weight: var(--shiki-dark-font-weight) !important;
  text-decoration: var(--shiki-dark-text-decoration) !important;
}

Because of how Astro is implemented, the correct way of using these would be using .astro-code instead of .shiki.

So the correct code and implementation should be

@media (prefers-color-scheme: dark) {
  .astro-code,
  .astro-code span {
    color: var(--shiki-dark) !important;
    background-color: var(--shiki-dark-bg) !important;
    /* Optional, if you also want font styles */
    font-style: var(--shiki-dark-font-style) !important;
    font-weight: var(--shiki-dark-font-weight) !important;
    text-decoration: var(--shiki-dark-text-decoration) !important;
  }
}
html.dark .astro-code,
html.dark .astro-code span {
  color: var(--shiki-dark) !important;
  background-color: var(--shiki-dark-bg) !important;
  /* Optional, if you also want font styles */
  font-style: var(--shiki-dark-font-style) !important;
  font-weight: var(--shiki-dark-font-weight) !important;
  text-decoration: var(--shiki-dark-text-decoration) !important;
}

@sarah11918
Copy link
Member

Hi! I'm closing this issue because, as I mentioned in the linked PR here, we have an open PR to address this! 🙌 Thank you for bringing it to our attention, and sorry we didn't get the PR completed before you needed it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something on the site isn't working
Projects
None yet
Development

No branches or pull requests

2 participants