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

Support CSS Variables #313

Closed
OskarGroth opened this issue Apr 17, 2022 · 1 comment · Fixed by #314
Closed

Support CSS Variables #313

OskarGroth opened this issue Apr 17, 2022 · 1 comment · Fixed by #314

Comments

@OskarGroth
Copy link
Contributor

OskarGroth commented Apr 17, 2022

Reposting this as an issue from another discussion around dark mode here:
#33

Shiki claims to support css-variables via a hack workaround using a special theme and last-second remap of colors. I see several issues with this approach:

  • No clear API, functionality is triggered by a theme name ('css-variables')
  • Limited to only 12 colors
  • No control over color names. I'm forced to use colors like shiki-token-punctuation for something semantically different to make use of all 12 colors.
  • The current COLOR_REPLACEMENT map contains errors, there is no entry for 000003:
    '#000002': 'var(--shiki-color-background)',
    Which leaves only 11 working colors.

Instead of the hacky and limited css-variables theme, why not just enable the user to supply their own color remap here:

const COLOR_REPLACEMENTS: Record<string, string> = {

And instead of the name check here:

if (_theme.name === 'css-variables') {

...add some new option on ShikiTheme like cssVariables: boolean? Or extend type to be light | dark | css, and trigger the remap based on that?

Seems to me that by doing this it would unlock full theming via CSS Variables and resolve all dark-mode issues, including my problems listed above. Users would be able to swap out any colors they'd like for a CSS variable instead.

@OskarGroth
Copy link
Contributor Author

Submitted my changes in #314. This is working perfect for my needs, I can now create a theme that is completely controlled by CSS, making it super easy to support Dark Mode. Would love to see this merged so let me know your feedback.

@orta orta closed this as completed in #314 Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant