Skip to content

Commit 26af1d2

Browse files
committed
sanitize the id name in the DOM
1 parent cbdc2fd commit 26af1d2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/theme/book.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ function playground_text(playground, hidden = true) {
320320
var theme;
321321
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
322322
if (theme === null || theme === undefined) {
323-
return default_theme;
323+
return default_theme.replace(/\W+/g, '_').toLowerCase();
324324
} else {
325-
return theme;
325+
return theme.replace(/\W+/g, '_').toLowerCase();
326326
}
327327
}
328328

@@ -364,7 +364,7 @@ function playground_text(playground, hidden = true) {
364364
var previousTheme = get_theme().replace(/\W+/g, '_').toLowerCase();
365365
var selectedTheme = theme.replace(/\W+/g, '_').toLowerCase();
366366
if (store) {
367-
try { localStorage.setItem('mdbook-theme', theme); } catch (e) { }
367+
try { localStorage.setItem('mdbook-theme', selectedTheme); } catch (e) { }
368368
}
369369

370370
try {
@@ -375,6 +375,9 @@ function playground_text(playground, hidden = true) {
375375
updateThemeSelected();
376376
}
377377

378+
// Sanitize theme id names
379+
themePopup.querySelectorAll("button").forEach(e=>{e.id=e.id.replace(/\W+/g, '_').toLowerCase();});
380+
378381
// Set theme
379382
var theme = get_theme();
380383

0 commit comments

Comments
 (0)