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

Pass themes option to Shiki? #18

Open
karlhorky opened this issue Feb 19, 2024 · 7 comments
Open

Pass themes option to Shiki? #18

karlhorky opened this issue Feb 19, 2024 · 7 comments

Comments

@karlhorky
Copy link
Contributor

karlhorky commented Feb 19, 2024

Similar to #17 (customization of the Slide container style), it would be nice to also be able to customize the Shiki themes array option, so that a different highlighter can be used:

themes: [
`${
basename(root) === 'remdx'
? `/packages/vite-plugin-remdx/`
: `/node_modules/@nkzw/vite-plugin-remdx/`
}lib/licht`,

Maybe it makes sense as an option for @nkzw/vite-plugin-remdx?

@karlhorky
Copy link
Contributor Author

Workaround

Currently, I am using patch-package to patch the node_modules/@nkzw/vite-plugin-remdx/lib/licht.json file to include the theme that I want from the tm-themes package

@cpojer
Copy link
Collaborator

cpojer commented Feb 19, 2024

Yes, providing the themes as a plugin option to vite-plugin-remdx makes sense. Happy to merge a PR for that.

Keep in mind that the licht.json colors are not actually used directly! It's a bit hacky, but they get swapped for CSS variables named like this: https://github.com/nkzw-tech/remdx/blob/main/packages/vite-plugin-remdx/lib/ColorReplacements.tsx#L4-L46

With this, you can simply define your theme in CSS and overwrite the defaults: https://github.com/nkzw-tech/remdx/blob/main/packages/remdx/style.css#L29-L142

This way your slide deck will look great in light and dark mode.

@karlhorky
Copy link
Contributor Author

Keep in mind that the licht.json colors are not actually used directly! It's a bit hacky, but they get swapped for CSS variables named like this: main/packages/vite-plugin-remdx/lib/ColorReplacements.tsx#L4-L46

With this, you can simply define your theme in CSS and overwrite the defaults: main/packages/remdx/style.css#L29-L142

This way your slide deck will look great in light and dark mode.

Ah, interesting, mapping the literal colors to CSS variables 🤔 Is it desirable to rework this a bit to make this less hacky? (or at least reducing the indirection)

Eg. what about using something like light-dark()?

@karlhorky
Copy link
Contributor Author

Yes, providing the themes as a plugin option to vite-plugin-remdx makes sense. Happy to merge a PR for that.

Ok, I'll try to a PR for this. Should this also include new entries to packages/vite-plugin-remdx/lib/ColorReplacements.tsx?

@cpojer
Copy link
Collaborator

cpojer commented May 30, 2024

Ah, interesting, mapping the literal colors to CSS variables 🤔 Is it desirable to rework this a bit to make this less hacky? (or at least reducing the indirection)

A proper fix to expose CSS variable directly should happen in Shiki itself. It doesn't really make sense to swap out one approach for another imho.

Ok, I'll try to a PR for this. Should this also include new entries to packages/vite-plugin-remdx/lib/ColorReplacements.tsx?

Yes.

@karlhorky
Copy link
Contributor Author

cc @antfu would exposing CSS variables from Shiki make sense as a feature?

If I'm understanding correctly, this would enable light and dark mode syntax highlighting (in this case for ReMDX)

@antfu
Copy link

antfu commented Jun 25, 2024

Are you talking about https://shiki.style/guide/theme-colors#css-variables-theme? It's already possible.

Just note that using CSS variables is a approximate approach (you won't get as accurate result as normal themes).

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

No branches or pull requests

3 participants