Skip to content

Commit bfe0e4d

Browse files
authored
gh-121035: Improve logging flow diagram for dark/light modes. (GH-121254)
1 parent 4f1e1df commit bfe0e4d

File tree

2 files changed

+62
-11
lines changed

2 files changed

+62
-11
lines changed

Doc/howto/logging.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,44 @@ following diagram.
385385
.. raw:: html
386386
:file: logging_flow.svg
387387

388+
.. raw:: html
389+
390+
<script>
391+
/*
392+
* This snippet is needed to handle the case where a light or dark theme is
393+
* chosen via the theme is selected in the page. We call the existing handler
394+
* and then add a dark-theme class to the body when the dark theme is selected.
395+
* The SVG styling (above) then does the rest.
396+
*
397+
* If the pydoc theme is updated to set the dark-theme class, this snippet
398+
* won't be needed any more.
399+
*/
400+
(function() {
401+
var oldActivateTheme = activateTheme;
402+
403+
function updateBody(theme) {
404+
let elem = document.body;
405+
406+
if (theme === 'dark') {
407+
elem.classList.add('dark-theme');
408+
}
409+
else {
410+
elem.classList.remove('dark-theme');
411+
}
412+
}
413+
414+
activateTheme = function(theme) {
415+
oldActivateTheme(theme);
416+
updateBody(theme);
417+
};
418+
/*
419+
* If the page is refreshed, make sure we update the body - the overriding
420+
* of activateTheme won't have taken effect yet.
421+
*/
422+
updateBody(localStorage.getItem('currentTheme') || 'auto');
423+
})();
424+
</script>
425+
388426
Loggers
389427
^^^^^^^
390428

Doc/howto/logging_flow.svg

Lines changed: 24 additions & 11 deletions
Loading

0 commit comments

Comments
 (0)