@@ -76,7 +76,9 @@ export function codeToHast(
7676 fg,
7777 bg,
7878 themeName,
79- rootStyle,
79+ rootStyle : options . rootStyle === false
80+ ? false
81+ : options . rootStyle ?? rootStyle ,
8082 } ,
8183 contextSource ,
8284 grammarState ,
@@ -102,24 +104,29 @@ export function tokensToHast(
102104 tabindex = '0' ,
103105 } = options
104106
107+ const properties : Element [ 'properties' ] = {
108+ class : `shiki ${ options . themeName || '' } ` ,
109+ }
110+
111+ if ( options . rootStyle !== false ) {
112+ if ( options . rootStyle != null )
113+ properties . style = options . rootStyle
114+ else
115+ properties . style = `background-color:${ options . bg } ;color:${ options . fg } `
116+ }
117+
118+ if ( tabindex !== false && tabindex != null )
119+ properties . tabindex = tabindex . toString ( )
120+
121+ for ( const [ key , value ] of Object . entries ( options . meta || { } ) ) {
122+ if ( ! key . startsWith ( '_' ) )
123+ properties [ key ] = value
124+ }
125+
105126 let preNode : Element = {
106127 type : 'element' ,
107128 tagName : 'pre' ,
108- properties : {
109- class : `shiki ${ options . themeName || '' } ` ,
110- style : options . rootStyle || `background-color:${ options . bg } ;color:${ options . fg } ` ,
111- ...( tabindex !== false && tabindex != null )
112- ? {
113- tabindex : tabindex . toString ( ) ,
114- }
115- : { } ,
116- ...Object . fromEntries (
117- Array . from (
118- Object . entries ( options . meta || { } ) ,
119- )
120- . filter ( ( [ key ] ) => ! key . startsWith ( '_' ) ) ,
121- ) ,
122- } ,
129+ properties,
123130 children : [ ] ,
124131 }
125132
0 commit comments