@@ -61,59 +61,37 @@ const diffNotationTransformer = transformerNotationDiff({
6161
6262function replaceShikiProperty (
6363 style : string ,
64- property : "background-color" | "--shiki-dark-bg" | "color" | "--shiki-dark"
64+ property :
65+ | "--shiki-light-bg"
66+ | "--shiki-dark-bg"
67+ | "--shiki-light"
68+ | "--shiki-dark"
6569) {
6670 const regex = new RegExp ( `${ property } :(?<hex>#[0-9a-z]{3,8})` , "i" ) ;
67-
68- let variableName : string ;
69- switch ( property ) {
70- case "background-color" : {
71- variableName = "--c-code-light-bg" ;
72- break ;
73- }
74- case "--shiki-dark-bg" : {
75- variableName = "--c-code-dark-bg" ;
76- break ;
77- }
78- case "color" : {
79- variableName = "--c-code-light" ;
80- break ;
81- }
82- case "--shiki-dark" : {
83- variableName = "--c-code-dark" ;
84- break ;
85- }
86- }
87-
71+ const variableName = property . replace ( "shiki" , "c-code" ) ;
8872 const hex = style . match ( regex ) ! . groups ! . hex ;
89-
9073 return style . replace ( regex , `${ variableName } :${ hex } ` ) ;
9174}
9275/**
93- * Workaround since 'shikiConfig' does not support 'defaultColor' and
94- * 'cssVariablePrefix' options yet. This manually does what happens when
95- * 'defaultColor' is set to 'false' and 'cssVariablePrefix' is set to
96- * '--c-code-'.
97- *
98- * @see
99- * {@link https://github.com/withastro/astro/issues/11238#issuecomment-2165715631 }
76+ * This does what 'cssVariablePrefix' does when set to `--c-code-` since
77+ * `shikiConfig` does not support it.
10078 */
101- const themeTransformer : ShikiTransformer = {
79+ const cssVariablePrefixTransformer : ShikiTransformer = {
10280 name : "theme" ,
10381 pre ( node ) {
10482 let style = node . properties . style as string ;
10583
106- style = replaceShikiProperty ( style , "background-color " ) ;
84+ style = replaceShikiProperty ( style , "--shiki-light-bg " ) ;
10785 style = replaceShikiProperty ( style , "--shiki-dark-bg" ) ;
108- style = replaceShikiProperty ( style , "color " ) ;
86+ style = replaceShikiProperty ( style , "--shiki-light " ) ;
10987 style = replaceShikiProperty ( style , "--shiki-dark" ) ;
11088
11189 node . properties . style = style ;
11290 } ,
11391 span ( node ) {
11492 let style = node . properties . style as string ;
11593
116- style = replaceShikiProperty ( style , "color " ) ;
94+ style = replaceShikiProperty ( style , "--shiki-light " ) ;
11795 style = replaceShikiProperty ( style , "--shiki-dark" ) ;
11896
11997 node . properties . style = style ;
@@ -455,11 +433,12 @@ export default <AstroUserConfig>{
455433 markdown : {
456434 smartypants : false ,
457435 shikiConfig : {
436+ defaultColor : false ,
458437 themes : { light : "slack-ochin" , dark : "slack-dark" } ,
459438 transformers : [
460439 classNamesTransformer ,
461440 diffNotationTransformer ,
462- themeTransformer
441+ cssVariablePrefixTransformer
463442 ]
464443 } ,
465444 remarkPlugins : [ remarkA11yEmoji ] ,
0 commit comments