@@ -305,7 +305,9 @@ function playground_text(playground, hidden = true) {
305305 themePopup . querySelectorAll ( '.theme-selected' ) . forEach ( function ( el ) {
306306 el . classList . remove ( 'theme-selected' ) ;
307307 } ) ;
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 ) { }
309311 }
310312
311313 function hideThemes ( ) {
@@ -318,9 +320,9 @@ function playground_text(playground, hidden = true) {
318320 var theme ;
319321 try { theme = localStorage . getItem ( 'mdbook-theme' ) ; } catch ( e ) { }
320322 if ( theme === null || theme === undefined ) {
321- return default_theme ;
323+ return default_theme . replace ( / \W + / g , '_' ) . toLowerCase ( ) ;
322324 } else {
323- return theme ;
325+ return theme . replace ( / \W + / g , '_' ) . toLowerCase ( ) ;
324326 }
325327 }
326328
@@ -331,13 +333,17 @@ function playground_text(playground, hidden = true) {
331333 stylesheets . ayuHighlight . disabled = true ;
332334 stylesheets . tomorrowNight . disabled = false ;
333335 stylesheets . highlight . disabled = true ;
334-
335336 ace_theme = "ace/theme/tomorrow_night" ;
336337 } else if ( theme == 'ayu' ) {
337338 stylesheets . ayuHighlight . disabled = false ;
338339 stylesheets . tomorrowNight . disabled = true ;
339340 stylesheets . highlight . disabled = true ;
340341 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" ;
341347 } else {
342348 stylesheets . ayuHighlight . disabled = true ;
343349 stylesheets . tomorrowNight . disabled = true ;
@@ -355,17 +361,23 @@ function playground_text(playground, hidden = true) {
355361 } ) ;
356362 }
357363
358- var previousTheme = get_theme ( ) ;
359-
364+ var previousTheme = get_theme ( ) . replace ( / \W + / g , '_' ) . toLowerCase ( ) ;
365+ var selectedTheme = theme . replace ( / \W + / g , '_' ) . toLowerCase ( ) ;
360366 if ( store ) {
361- try { localStorage . setItem ( 'mdbook-theme' , theme ) ; } catch ( e ) { }
367+ try { localStorage . setItem ( 'mdbook-theme' , selectedTheme ) ; } catch ( e ) { }
362368 }
363369
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+
366375 updateThemeSelected ( ) ;
367376 }
368377
378+ // Sanitize theme id names
379+ themePopup . querySelectorAll ( "button" ) . forEach ( e => { e . id = e . id . replace ( / \W + / g, '_' ) . toLowerCase ( ) ; } ) ;
380+
369381 // Set theme
370382 var theme = get_theme ( ) ;
371383
0 commit comments