@@ -4,6 +4,10 @@ import {
44 type Highlighter ,
55 type BundledLanguage ,
66} from 'shiki' ;
7+ import { palenightTheme } from '../../themes/palenight' ;
8+ import { lighthouseTheme } from '../../themes/lighthouse' ;
9+ import { monacoThemeToShiki } from '../../themes/shiki-adapter' ;
10+ import { ELB_THEME_DARK , ELB_THEME_LIGHT } from '../../themes/names' ;
711
812export interface CodeStaticProps {
913 code : string ;
@@ -26,12 +30,29 @@ const LANGS: readonly BundledLanguage[] = [
2630 'markdown' ,
2731] ;
2832
33+ // Derive Shiki themes from the same Monaco theme objects CodeBox uses,
34+ // so CodeView (Shiki) and CodeBox (Monaco) render identical colors.
35+ // Names match Monaco's `monaco.editor.setTheme(...)` keys.
36+ const ELB_SHIKI_LIGHT = monacoThemeToShiki ( lighthouseTheme , {
37+ name : ELB_THEME_LIGHT ,
38+ type : 'light' ,
39+ defaultBackground : '#ffffff' ,
40+ defaultForeground : '#24292E' ,
41+ } ) ;
42+
43+ const ELB_SHIKI_DARK = monacoThemeToShiki ( palenightTheme , {
44+ name : ELB_THEME_DARK ,
45+ type : 'dark' ,
46+ defaultBackground : '#292d3e' ,
47+ defaultForeground : '#bfc7d5' ,
48+ } ) ;
49+
2950let highlighterPromise : Promise < Highlighter > | null = null ;
3051
3152function getHighlighter ( ) : Promise < Highlighter > {
3253 if ( ! highlighterPromise ) {
3354 highlighterPromise = createHighlighter ( {
34- themes : [ 'dark-plus' , 'light-plus' ] ,
55+ themes : [ ELB_SHIKI_LIGHT , ELB_SHIKI_DARK ] ,
3556 langs : [ ...LANGS ] ,
3657 } ) ;
3758 }
@@ -85,7 +106,7 @@ export function CodeStatic({
85106 if ( cancelled ) return ;
86107 const rendered = highlighter . codeToHtml ( code , {
87108 lang : resolveLang ( language ) ,
88- theme : activeTheme === 'dark' ? 'dark-plus' : 'light-plus' ,
109+ theme : activeTheme === 'dark' ? ELB_THEME_DARK : ELB_THEME_LIGHT ,
89110 } ) ;
90111 setHtml ( rendered ) ;
91112 } ) ;
@@ -94,7 +115,9 @@ export function CodeStatic({
94115 } ;
95116 } , [ code , language , activeTheme ] ) ;
96117
118+ const wrapperClass = `elb-code-static${ className ? ` ${ className } ` : '' } ` ;
119+
97120 return (
98- < div className = { className } dangerouslySetInnerHTML = { { __html : html } } />
121+ < div className = { wrapperClass } dangerouslySetInnerHTML = { { __html : html } } />
99122 ) ;
100123}
0 commit comments