File tree Expand file tree Collapse file tree 2 files changed +62
-11
lines changed
Expand file tree Collapse file tree 2 files changed +62
-11
lines changed Original file line number Diff line number Diff 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+
388426Loggers
389427^^^^^^^
390428
You can’t perform that action at this time.
0 commit comments