@@ -309,7 +309,9 @@ function playground_text(playground, hidden = true) {
309
309
themePopup . querySelectorAll ( '.theme-selected' ) . forEach ( function ( el ) {
310
310
el . classList . remove ( 'theme-selected' ) ;
311
311
} ) ;
312
- themePopup . querySelector ( "button#" + get_theme ( ) ) . classList . add ( 'theme-selected' ) ;
312
+ try {
313
+ themePopup . querySelector ( "button#" + get_theme ( ) ) . classList . add ( 'theme-selected' ) ;
314
+ } catch ( e ) { }
313
315
}
314
316
315
317
function hideThemes ( ) {
@@ -322,9 +324,9 @@ function playground_text(playground, hidden = true) {
322
324
var theme ;
323
325
try { theme = localStorage . getItem ( 'mdbook-theme' ) ; } catch ( e ) { }
324
326
if ( theme === null || theme === undefined || ! themeIds . includes ( theme ) ) {
325
- return default_theme ;
327
+ return default_theme . replace ( / \W + / g , '_' ) . toLowerCase ( ) ;
326
328
} else {
327
- return theme ;
329
+ return theme . replace ( / \W + / g , '_' ) . toLowerCase ( ) ;
328
330
}
329
331
}
330
332
@@ -335,13 +337,17 @@ function playground_text(playground, hidden = true) {
335
337
stylesheets . ayuHighlight . disabled = true ;
336
338
stylesheets . tomorrowNight . disabled = false ;
337
339
stylesheets . highlight . disabled = true ;
338
-
339
340
ace_theme = "ace/theme/tomorrow_night" ;
340
341
} else if ( theme == 'ayu' ) {
341
342
stylesheets . ayuHighlight . disabled = false ;
342
343
stylesheets . tomorrowNight . disabled = true ;
343
344
stylesheets . highlight . disabled = true ;
344
345
ace_theme = "ace/theme/tomorrow_night" ;
346
+ } else if ( theme == 'rust' || theme == 'light' ) {
347
+ stylesheets . ayuHighlight . disabled = true ;
348
+ stylesheets . tomorrowNight . disabled = true ;
349
+ stylesheets . highlight . disabled = false ;
350
+ ace_theme = "ace/theme/dawn" ;
345
351
} else {
346
352
stylesheets . ayuHighlight . disabled = true ;
347
353
stylesheets . tomorrowNight . disabled = true ;
@@ -359,17 +365,23 @@ function playground_text(playground, hidden = true) {
359
365
} ) ;
360
366
}
361
367
362
- var previousTheme = get_theme ( ) ;
363
-
368
+ var previousTheme = get_theme ( ) . replace ( / \W + / g , '_' ) . toLowerCase ( ) ;
369
+ var selectedTheme = theme . replace ( / \W + / g , '_' ) . toLowerCase ( ) ;
364
370
if ( store ) {
365
- try { localStorage . setItem ( 'mdbook-theme' , theme ) ; } catch ( e ) { }
371
+ try { localStorage . setItem ( 'mdbook-theme' , selectedTheme ) ; } catch ( e ) { }
366
372
}
367
373
368
- html . classList . remove ( previousTheme ) ;
369
- html . classList . add ( theme ) ;
374
+ try {
375
+ html . classList . remove ( previousTheme ) ;
376
+ html . classList . add ( selectedTheme ) ;
377
+ } catch ( e ) { }
378
+
370
379
updateThemeSelected ( ) ;
371
380
}
372
381
382
+ // Sanitize theme id names
383
+ themePopup . querySelectorAll ( "button" ) . forEach ( e => { e . id = e . id . replace ( / \W + / g, '_' ) . toLowerCase ( ) ; } ) ;
384
+
373
385
// Set theme
374
386
var theme = get_theme ( ) ;
375
387
0 commit comments