11// `shiki/core` entry does not include any themes or languages or the wasm binary.
2- import { createHighlighterCore , type ThemeRegistrationRaw } from 'shiki/core' ;
3- import { createJavaScriptRegexEngine } from 'shiki/engine- javascript.mjs ' ;
2+ import { createHighlighterCore , type DynamicImportThemeRegistration , type ThemeRegistration } from 'shiki/core' ;
3+ import { createJavaScriptRegexEngine } from 'shiki/engine/ javascript' ;
44
55// directly import the theme and language modules, only the ones you imported will be bundled.
6- import themeGitHubDark from 'shiki/themes/github-dark-default.mjs' ;
7- import themeGitHubLight from 'shiki/themes/github-light-default.mjs' ;
86
9- import languageJavaScript from 'shiki/langs/js.mjs' ;
10- import languagePython from 'shiki/langs/py.mjs' ;
11- import languageTypeScript from 'shiki/langs/ts.mjs' ;
7+ // TODO: [P*] Check if this hurts tree shaking.
8+ import { bundledLanguages } from 'shiki/langs' ;
9+ import { bundledThemes } from 'shiki/themes' ;
10+
11+ async function adjustTheme ( getTheme : DynamicImportThemeRegistration ) : Promise < ThemeRegistration > {
12+ const { default : theme } = await getTheme ( ) ;
1213
13- function addjustTheme ( theme : ThemeRegistrationRaw ) : ThemeRegistrationRaw {
1414 return {
1515 ...theme ,
1616 colors : {
@@ -20,10 +20,13 @@ function addjustTheme(theme: ThemeRegistrationRaw): ThemeRegistrationRaw {
2020 } ;
2121}
2222
23- function createHighlighter ( ) {
23+ async function createHighlighter ( ) {
2424 return createHighlighterCore ( {
25- themes : [ addjustTheme ( themeGitHubDark ) , addjustTheme ( themeGitHubLight ) ] ,
26- langs : [ languageJavaScript , languagePython , languageTypeScript ] ,
25+ themes : [
26+ await adjustTheme ( bundledThemes [ 'github-dark-default' ] ) ,
27+ await adjustTheme ( bundledThemes [ 'github-light-default' ] )
28+ ] ,
29+ langs : [ bundledLanguages . javascript , bundledLanguages . python , bundledLanguages . typescript ] ,
2730 engine : createJavaScriptRegexEngine ( )
2831 } ) ;
2932}
0 commit comments