@@ -88,7 +88,7 @@ export async function highlight(
88
88
89
89
if ( lang ) {
90
90
const langLoaded = highlighter . getLoadedLanguages ( ) . includes ( lang as any )
91
- if ( ! langLoaded ) {
91
+ if ( ! langLoaded && lang !== 'ansi' ) {
92
92
console . warn (
93
93
c . yellow (
94
94
`The language '${ lang } ' is not loaded, falling back to '${
@@ -127,42 +127,28 @@ export async function highlight(
127
127
return s
128
128
}
129
129
130
- if ( hasSingleTheme ) {
130
+ str = removeMustache ( str )
131
+
132
+ const codeToHtml = ( theme : IThemeRegistration ) => {
131
133
return cleanup (
132
134
restoreMustache (
133
- highlighter . codeToHtml ( removeMustache ( str ) , {
134
- lang,
135
- lineOptions,
136
- theme : getThemeName ( theme )
137
- } )
135
+ lang === 'ansi'
136
+ ? highlighter . ansiToHtml ( str , {
137
+ lineOptions,
138
+ theme : getThemeName ( theme )
139
+ } )
140
+ : highlighter . codeToHtml ( str , {
141
+ lang,
142
+ lineOptions,
143
+ theme : getThemeName ( theme )
144
+ } )
138
145
)
139
146
)
140
147
}
141
148
142
- const dark = addClass (
143
- cleanup (
144
- highlighter . codeToHtml ( str , {
145
- lang,
146
- lineOptions,
147
- theme : getThemeName ( theme . dark )
148
- } )
149
- ) ,
150
- 'vp-code-dark' ,
151
- 'pre'
152
- )
153
-
154
- const light = addClass (
155
- cleanup (
156
- highlighter . codeToHtml ( str , {
157
- lang,
158
- lineOptions,
159
- theme : getThemeName ( theme . light )
160
- } )
161
- ) ,
162
- 'vp-code-light' ,
163
- 'pre'
164
- )
165
-
149
+ if ( hasSingleTheme ) return codeToHtml ( theme )
150
+ const dark = addClass ( codeToHtml ( theme . dark ) , 'vp-code-dark' , 'pre' )
151
+ const light = addClass ( codeToHtml ( theme . light ) , 'vp-code-light' , 'pre' )
166
152
return dark + light
167
153
}
168
154
}
0 commit comments