Skip to content

Commit bd43fcf

Browse files
committed
[3.12] pythongh-121035: Improve logging flow diagram for dark/light modes. (pythonGH-121254)
(cherry picked from commit bfe0e4d) Co-authored-by: Vinay Sajip <[email protected]>
1 parent 4ade772 commit bd43fcf

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
@@ -384,6 +384,44 @@ following diagram.
384384
.. raw:: html
385385
:file: logging_flow.svg
386386

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

Doc/howto/logging_flow.svg

Lines changed: 24 additions & 11 deletions
Loading

0 commit comments

Comments
 (0)