How to load a custom theme for Shiki highlighting? #4702
-
I was able to load custom grammars with preloaded themes this way: import grammar1 from './shiki/myGrammar1.tmLanguage.json' with { type: 'json'}
import grammar2 from './shiki/myGrammar2.tmLanguage.json' with { type: 'json'}
export default defineConfig({
markdown: {
shikiSetup: async shiki => {
await shiki.loadLanguage(grammar1)
await shiki.loadLanguage(grammar2)
},
theme: {
dark: 'github-dark',
light: 'github-light',
},
},
} I'd like to load my own themes for both dark and light. I've been trying various things, but nothing seems to work. My latest try is with loadtheme, but when I do this, I get an argument of type error asking for a BundledTheme or a ThemeInput instead of the Markdown theme file in JSON that I am providing. shikiSetup: async shiki => {
await shiki.loadLanguage(grammar1)
await shiki.loadLanguage(grammar2)
await shiki.loadTheme(theme1)
await shiki.loadTheme(theme2)
},
theme: {
dark: theme1,
light: theme2,
}, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
What kind of theme file do you have? It needs textmate theme in json. If by "type error" you meant errors shown by TypeScript, you can safely ts-ignore it or cast it as any. Inferring deep types from JSON doesn't work properly. You don't need to call loadTheme though. You don't need to call loadLanguage either, you can just pass https://stackblitz.com/edit/vite-cz6amcgi?file=docs/.vitepress/config.ts |
Beta Was this translation helpful? Give feedback.
-
Hmm.. Thanks, your example works very nicely. I was testing with https://github.com/shikijs/textmate-grammars-themes/blob/main/packages/tm-themes/themes/github-dark.json It was not working, but your JSON file works. I'll start with that. Thanks a bunch. |
Beta Was this translation helpful? Give feedback.
What kind of theme file do you have? It needs textmate theme in json. If by "type error" you meant errors shown by TypeScript, you can safely ts-ignore it or cast it as any. Inferring deep types from JSON doesn't work properly.
You don't need to call loadTheme though. You don't need to call loadLanguage either, you can just pass
languages: [grammar1, grammar2]
.https://stackblitz.com/edit/vite-cz6amcgi?file=docs/.vitepress/config.ts