Skip to content

Commit 75a87a5

Browse files
committed
Fix toggling dark mode with highlightjs: false (in mkdocs theme)
When highlightjs is disabled, some HTML elements don't exist. But the code didn't expect this and had an error, interrupting the entire action of toggling dark mode.
1 parent 252e8dc commit 75a87a5

File tree

1 file changed

+4
-1
lines changed
  • packages/properdocs-theme-mkdocs/properdocs_theme_mkdocs/js

1 file changed

+4
-1
lines changed

packages/properdocs-theme-mkdocs/properdocs_theme_mkdocs/js/darkmode.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
function setColorMode(mode) {
22
// Switch between light/dark theme. `mode` is a string value of either 'dark' or 'light'.
3+
document.documentElement.setAttribute('data-bs-theme', mode);
34
var hljs_light = document.getElementById('hljs-light'),
45
hljs_dark = document.getElementById('hljs-dark');
5-
document.documentElement.setAttribute('data-bs-theme', mode);
6+
if (hljs_light == null || hljs_dark == null) {
7+
return;
8+
}
69
if (mode == 'dark') {
710
hljs_light.disabled = true;
811
hljs_dark.disabled = false;

0 commit comments

Comments
 (0)