@@ -175,75 +175,75 @@ function createPlugin() {
175
175
warnMissingLanguageFile ( missingScopeName , scope ) ;
176
176
} ) ;
177
177
178
- const colorThemeValue =
179
- typeof colorTheme === 'function'
180
- ? colorTheme ( {
181
- markdownNode,
182
- codeFenceNode : node ,
183
- parsedOptions : options ,
184
- language : languageName
185
- } )
186
- : colorTheme ;
187
- const colorThemeSettings = createColorThemeSettings ( colorThemeValue ) ;
188
- const themeClassNames = createThemeClassNames ( colorThemeSettings ) ;
189
- for ( const setting in colorThemeSettings ) {
190
- const colorThemeIdentifier = colorThemeSettings [ setting ] ;
191
- if ( ! colorThemeIdentifier ) continue ;
192
- await downloadExtensionIfNeeded ( {
193
- type : 'theme' ,
194
- name : colorThemeIdentifier ,
195
- extensions,
196
- cache,
197
- languageAliases,
198
- extensionDir : extensionDataDirectory
199
- } ) ;
178
+ try {
179
+ const colorThemeValue =
180
+ typeof colorTheme === 'function'
181
+ ? colorTheme ( {
182
+ markdownNode,
183
+ codeFenceNode : node ,
184
+ parsedOptions : options ,
185
+ language : languageName
186
+ } )
187
+ : colorTheme ;
188
+ const colorThemeSettings = createColorThemeSettings ( colorThemeValue ) ;
189
+ const themeClassNames = createThemeClassNames ( colorThemeSettings ) ;
190
+ for ( const setting in colorThemeSettings ) {
191
+ const colorThemeIdentifier = colorThemeSettings [ setting ] ;
192
+ if ( ! colorThemeIdentifier ) continue ;
193
+ await downloadExtensionIfNeeded ( {
194
+ type : 'theme' ,
195
+ name : colorThemeIdentifier ,
196
+ extensions,
197
+ cache,
198
+ languageAliases,
199
+ extensionDir : extensionDataDirectory
200
+ } ) ;
200
201
201
- const themeClassName = themeClassNames [ setting ] ;
202
- const themeCache = await cache . get ( 'themes' ) ;
203
- const colorThemePath =
204
- getThemeLocation ( colorThemeIdentifier , themeCache ) ||
205
- path . resolve ( markdownNode . fileAbsolutePath , colorThemeIdentifier ) ;
202
+ const themeClassName = themeClassNames [ setting ] ;
203
+ const themeCache = await cache . get ( 'themes' ) ;
204
+ const colorThemePath =
205
+ getThemeLocation ( colorThemeIdentifier , themeCache ) ||
206
+ path . resolve ( markdownNode . fileAbsolutePath , colorThemeIdentifier ) ;
206
207
207
- const { resultRules : tokenColors , resultColors : settings } = loadColorTheme ( colorThemePath ) ;
208
- const defaultTokenColors = {
209
- settings : {
210
- foreground : settings [ 'editor.foreground' ] || settings . foreground ,
211
- background : settings [ 'editor.background' ] || settings . background
212
- }
213
- } ;
208
+ const { resultRules : tokenColors , resultColors : settings } = loadColorTheme ( colorThemePath ) ;
209
+ const defaultTokenColors = {
210
+ settings : {
211
+ foreground : settings [ 'editor.foreground' ] || settings . foreground ,
212
+ background : settings [ 'editor.background' ] || settings . background
213
+ }
214
+ } ;
214
215
215
- registry . setTheme ( { settings : [ defaultTokenColors , ...tokenColors ] } ) ;
216
- if ( ! stylesheets [ themeClassName ] ) {
217
- const rules = [
218
- renderRule ( themeClassName , getStylesFromSettings ( settings ) ) ,
219
- ...( scope
220
- ? prefixRules (
221
- generateTokensCSSForColorMap (
222
- registry . getColorMap ( ) . map ( color => replaceColor ( color , colorThemeIdentifier ) )
223
- ) . split ( '\n' ) ,
224
- `.${ themeClassName } `
225
- )
226
- : [ ] )
227
- ] ;
216
+ registry . setTheme ( { settings : [ defaultTokenColors , ...tokenColors ] } ) ;
217
+ if ( ! stylesheets [ themeClassName ] ) {
218
+ const rules = [
219
+ renderRule ( themeClassName , getStylesFromSettings ( settings ) ) ,
220
+ ...( scope
221
+ ? prefixRules (
222
+ generateTokensCSSForColorMap (
223
+ registry . getColorMap ( ) . map ( color => replaceColor ( color , colorThemeIdentifier ) )
224
+ ) . split ( '\n' ) ,
225
+ `.${ themeClassName } `
226
+ )
227
+ : [ ] )
228
+ ] ;
228
229
229
- if ( setting === 'prefersDarkTheme' ) {
230
- stylesheets [ themeClassName ] = prefersDark ( rules ) ;
231
- } else if ( setting === 'prefersLightTheme' ) {
232
- stylesheets [ themeClassName ] = prefersLight ( rules ) ;
233
- } else {
234
- stylesheets [ themeClassName ] = rules . join ( '\n' ) ;
230
+ if ( setting === 'prefersDarkTheme' ) {
231
+ stylesheets [ themeClassName ] = prefersDark ( rules ) ;
232
+ } else if ( setting === 'prefersLightTheme' ) {
233
+ stylesheets [ themeClassName ] = prefersLight ( rules ) ;
234
+ } else {
235
+ stylesheets [ themeClassName ] = rules . join ( '\n' ) ;
236
+ }
235
237
}
236
238
}
237
- }
238
239
239
- const rawLines = text . split ( / \r ? \n / ) ;
240
- const htmlLines = [ ] ;
241
- /** @type {import('vscode-textmate').ITokenTypeMap } */
242
- let tokenTypes = { } ;
243
- /** @type {number } */
244
- let languageId ;
240
+ const rawLines = text . split ( / \r ? \n / ) ;
241
+ const htmlLines = [ ] ;
242
+ /** @type {import('vscode-textmate').ITokenTypeMap } */
243
+ let tokenTypes = { } ;
244
+ /** @type {number } */
245
+ let languageId ;
245
246
246
- try {
247
247
if ( scope ) {
248
248
const grammarData = getGrammar ( scope , grammarCache ) ;
249
249
languageId = grammarData . languageId ;
@@ -285,32 +285,32 @@ function createPlugin() {
285
285
286
286
htmlLines . push ( [ `<span class="${ className } ">` , htmlLine , `</span>` ] . join ( '' ) ) ;
287
287
}
288
+
289
+ const className = joinClassNames ( wrapperClassName , joinThemeClassNames ( themeClassNames ) , 'vscode-highlight' ) ;
290
+ node . type = 'html' ;
291
+ node . value = [
292
+ `<pre class="${ className } " data-language="${ languageName } ">` ,
293
+ `<code class="vscode-highlight-code">` ,
294
+ htmlLines . join ( '\n' ) ,
295
+ `</code>` ,
296
+ `</pre>`
297
+ ] . join ( '' ) ;
298
+
299
+ const themeNames = Object . keys ( stylesheets ) ;
300
+ if ( themeNames . length ) {
301
+ markdownAST . children . push ( {
302
+ type : 'html' ,
303
+ value : [
304
+ '<style class="vscode-highlight-styles">' ,
305
+ injectStyles ? styles : '' ,
306
+ themeNames . map ( theme => stylesheets [ theme ] ) . join ( '\n' ) ,
307
+ '</style>'
308
+ ] . join ( '' )
309
+ } ) ;
310
+ }
288
311
} finally {
289
312
unlockRegistry ( ) ;
290
313
}
291
-
292
- const className = joinClassNames ( wrapperClassName , joinThemeClassNames ( themeClassNames ) , 'vscode-highlight' ) ;
293
- node . type = 'html' ;
294
- node . value = [
295
- `<pre class="${ className } " data-language="${ languageName } ">` ,
296
- `<code class="vscode-highlight-code">` ,
297
- htmlLines . join ( '\n' ) ,
298
- `</code>` ,
299
- `</pre>`
300
- ] . join ( '' ) ;
301
- }
302
-
303
- const themeNames = Object . keys ( stylesheets ) ;
304
- if ( themeNames . length ) {
305
- markdownAST . children . push ( {
306
- type : 'html' ,
307
- value : [
308
- '<style class="vscode-highlight-styles">' ,
309
- injectStyles ? styles : '' ,
310
- themeNames . map ( theme => stylesheets [ theme ] ) . join ( '\n' ) ,
311
- '</style>'
312
- ] . join ( '' )
313
- } ) ;
314
314
}
315
315
}
316
316
return textmateHighlight ;
0 commit comments