Skip to content

Commit b335dbf

Browse files
committed
sanitize theme names
Update book.js Update book.js Update book.js Revert "Update book.js" This reverts commit 0ed9477. Update book.js
1 parent 09b135d commit b335dbf

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/theme/book.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -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() {
@@ -360,13 +362,12 @@ function playground_text(playground, hidden = true) {
360362
}
361363

362364
var previousTheme = get_theme();
363-
364365
if (store) {
365366
try { localStorage.setItem('mdbook-theme', theme); } catch (e) { }
366367
}
367368

368-
html.classList.remove(previousTheme);
369-
html.classList.add(theme);
369+
html.classList.remove(previousTheme.replace(/\W+/g, '_').toLowerCase());
370+
html.classList.add(theme.replace(/\W+/g, '_').toLowerCase());
370371
updateThemeSelected();
371372
}
372373

src/theme/index.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
var html = document.querySelector('html');
8686
html.classList.remove('no-js')
8787
html.classList.remove('{{ default_theme }}')
88-
html.classList.add(theme);
88+
html.classList.add(theme.replace(/\W+/g, '_').toLowerCase());
8989
html.classList.add('js');
9090
</script>
9191

0 commit comments

Comments
 (0)