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