Skip to content

Commit 80646e3

Browse files
committed
sanitize theme names
1 parent ded0e41 commit 80646e3

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/theme/book.js

+6-5
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-
var themeId = theme.replace(/\W+/g, '_').toLowerCase();
364365
if (store) {
365-
try { localStorage.setItem('mdbook-theme', themeId); } catch (e) { }
366+
try { localStorage.setItem('mdbook-theme', theme); } catch (e) { }
366367
}
367368

368-
html.classList.remove(previousTheme);
369-
html.classList.add(themeId);
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)