@@ -70,7 +70,33 @@ export async function createMarkdownRenderer(
7070 markedShiki ( {
7171 highlight ( code , lang , _ ) {
7272 try {
73- return highlighter . codeToHtml ( code , { lang, themes } ) ;
73+ const html = highlighter . codeToHtml ( code , { lang, themes } ) ;
74+
75+ const colorMap : Record < string , string > = {
76+ '6f42c1' : 'var(--shiki-purple)' ,
77+ '032f62' : 'var(--shiki-dark-blue)' ,
78+ '24292e' : 'var(--shiki-navy)' ,
79+ d73a49 : 'var(--shiki-red)' ,
80+ '005cc5' : 'var(--shiki-blue)' ,
81+ '22863a' : 'var(--shiki-green)' ,
82+ e36209 : 'var(--shiki-orange)' ,
83+ } ;
84+
85+ const processed = html . replace (
86+ / s t y l e = " ( [ ^ " ] * ) " / g,
87+ ( _m , styleContent ) => {
88+ const replaced = styleContent . replace (
89+ / # ( [ 0 - 9 a - f A - F ] { 6 } ) / g,
90+ ( _full : any , hex : string ) => {
91+ const rep = colorMap [ hex . toLowerCase ( ) ] ;
92+ return rep ?? `#${ hex } ` ;
93+ }
94+ ) ;
95+ return `style="${ replaced } "` ;
96+ }
97+ ) ;
98+
99+ return processed ;
74100 } catch {
75101 return `<pre><code>${ sanitizer ( code ) } </code></pre>` ;
76102 }
0 commit comments