@@ -309,7 +309,9 @@ function playground_text(playground, hidden = true) {
309309 themePopup . querySelectorAll ( '.theme-selected' ) . forEach ( function ( el ) {
310310 el . classList . remove ( 'theme-selected' ) ;
311311 } ) ;
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 ) { }
313315 }
314316
315317 function hideThemes ( ) {
@@ -322,9 +324,9 @@ function playground_text(playground, hidden = true) {
322324 var theme ;
323325 try { theme = localStorage . getItem ( 'mdbook-theme' ) ; } catch ( e ) { }
324326 if ( theme === null || theme === undefined || ! themeIds . includes ( theme ) ) {
325- return default_theme ;
327+ return default_theme . replace ( / \W + / g , '_' ) . toLowerCase ( ) ;
326328 } else {
327- return theme ;
329+ return theme . replace ( / \W + / g , '_' ) . toLowerCase ( ) ;
328330 }
329331 }
330332
@@ -335,13 +337,17 @@ function playground_text(playground, hidden = true) {
335337 stylesheets . ayuHighlight . disabled = true ;
336338 stylesheets . tomorrowNight . disabled = false ;
337339 stylesheets . highlight . disabled = true ;
338-
339340 ace_theme = "ace/theme/tomorrow_night" ;
340341 } else if ( theme == 'ayu' ) {
341342 stylesheets . ayuHighlight . disabled = false ;
342343 stylesheets . tomorrowNight . disabled = true ;
343344 stylesheets . highlight . disabled = true ;
344345 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" ;
345351 } else {
346352 stylesheets . ayuHighlight . disabled = true ;
347353 stylesheets . tomorrowNight . disabled = true ;
@@ -359,17 +365,23 @@ function playground_text(playground, hidden = true) {
359365 } ) ;
360366 }
361367
362- var previousTheme = get_theme ( ) ;
363-
368+ var previousTheme = get_theme ( ) . replace ( / \W + / g , '_' ) . toLowerCase ( ) ;
369+ var selectedTheme = theme . replace ( / \W + / g , '_' ) . toLowerCase ( ) ;
364370 if ( store ) {
365- try { localStorage . setItem ( 'mdbook-theme' , theme ) ; } catch ( e ) { }
371+ try { localStorage . setItem ( 'mdbook-theme' , selectedTheme ) ; } catch ( e ) { }
366372 }
367373
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+
370379 updateThemeSelected ( ) ;
371380 }
372381
382+ // Sanitize theme id names
383+ themePopup . querySelectorAll ( "button" ) . forEach ( e => { e . id = e . id . replace ( / \W + / g, '_' ) . toLowerCase ( ) ; } ) ;
384+
373385 // Set theme
374386 var theme = get_theme ( ) ;
375387
0 commit comments