From b62605d50fe1b123e9e9bd19a3230c6dc817ac79 Mon Sep 17 00:00:00 2001
From: Vinay Sajip <vinay_sajip@yahoo.co.uk>
Date: Wed, 3 Jul 2024 11:01:50 +0100
Subject: [PATCH] [3.13] gh-121035: Improve logging flow diagram for dark/light
 modes. (GH-121254) (GH-121317)

(cherry picked from commit bfe0e4d7696647a546110328510bdb98146ad2f2)
---
 Doc/howto/logging.rst      | 38 ++++++++++++++++++++++++++++++++++++++
 Doc/howto/logging_flow.svg | 35 ++++++++++++++++++++++++-----------
 2 files changed, 62 insertions(+), 11 deletions(-)

diff --git a/Doc/howto/logging.rst b/Doc/howto/logging.rst
index 316b16aa796af4..9c55233e910f17 100644
--- a/Doc/howto/logging.rst
+++ b/Doc/howto/logging.rst
@@ -385,6 +385,44 @@ following diagram.
 .. raw:: html
    :file: logging_flow.svg
 
+.. raw:: html
+
+   <script>
+   /*
+    * This snippet is needed to handle the case where a light or dark theme is
+    * chosen via the theme is selected in the page. We call the existing handler
+    * and then add a dark-theme class to the body when the dark theme is selected.
+    * The SVG styling (above) then does the rest.
+    *
+    * If the pydoc theme is updated to set the dark-theme class, this snippet
+    * won't be needed any more.
+    */
+   (function() {
+     var oldActivateTheme = activateTheme;
+
+     function updateBody(theme) {
+        let elem = document.body;
+
+        if (theme === 'dark') {
+            elem.classList.add('dark-theme');
+        }
+        else {
+            elem.classList.remove('dark-theme');
+        }
+     }
+
+     activateTheme = function(theme) {
+        oldActivateTheme(theme);
+        updateBody(theme);
+     };
+     /*
+      * If the page is refreshed, make sure we update the body - the overriding
+      * of activateTheme won't have taken effect yet.
+      */
+      updateBody(localStorage.getItem('currentTheme') || 'auto');
+   })();
+   </script>
+
 Loggers
 ^^^^^^^
 
diff --git a/Doc/howto/logging_flow.svg b/Doc/howto/logging_flow.svg
index a5f656b1df0b42..9807323b7190d6 100644
--- a/Doc/howto/logging_flow.svg
+++ b/Doc/howto/logging_flow.svg
@@ -1,9 +1,9 @@
 <svg width="22cm" height="23cm" viewBox="1 1 439 446" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
   <!-- Invert color in dark mode -->
   <style type="text/css">
-      svg {
-        background-color: transparent !important;
-      }
+    svg {
+      background-color: transparent !important;
+    }
     line {
       stroke: #000000;
       fill: none;
@@ -16,7 +16,7 @@
       stroke-opacity: 1;
     }
     polygon.filled {
-      fill: #ff0000;
+      fill: #000000;
     }
     polyline {
       fill: none;
@@ -36,6 +36,9 @@
       polygon, rect, polyline, line {
         stroke: #ffffff;
       }
+      polygon.filled {
+        fill: #ffffff;
+      }
       text {
         fill: #ffffff;
       }
@@ -43,6 +46,15 @@
         filter: invert(100%) hue-rotate(180deg) saturate(1.25);
       }
     }
+    body.dark-theme polygon, body.dark-theme rect, body.dark-theme polyline, body.dark-theme line {
+      stroke: #ffffff;
+    }
+    body.dark-theme polygon.filled {
+      fill: #ffffff;
+    }
+    body.dark-theme text {
+      fill: #ffffff;
+    }
   </style>
 
   <defs />
@@ -57,7 +69,7 @@
       <rect x="81.5533" y="106.469" width="44.45" height="25.9333" rx="0" ry="0" />
       <text font-size="6.77333" style="text-anchor: middle;" x="103.778" y="117.256">
         <tspan x="103.778" y="117.256">Create</tspan>
-        <tspan x="103.778" y="125.723">LogRecord</tspan>
+        <tspan x="103.778" y="125.723" style="font-family: monospace">LogRecord</tspan>
       </text>
     </g>
     <g>
@@ -100,7 +112,7 @@
     <g>
       <rect x="75.2033" y="249.478" width="57.15" height="34.4" rx="0" ry="0" />
       <text font-size="6.77333" style="text-anchor: middle;" x="103.778" y="260.265">
-        <tspan x="103.778" y="260.265">Pass to</tspan>
+        <tspan x="103.778" y="260.265">Pass record to</tspan>
         <tspan x="103.778" y="268.732">handlers of</tspan>
         <tspan x="103.778" y="277.198">current logger</tspan>
       </text>
@@ -135,16 +147,17 @@
     </g>
     <g>
       <rect x="298.963" y="312.257" width="57.75" height="25.9333" rx="0" ry="0" />
-      <text font-size="6.77333" style="text-anchor: middle;" x="327.838" y="323.044">
-        <tspan x="327.838" y="324.100">Use lastResort</tspan>
-        <tspan x="327.838" y="332.567">handler</tspan>
+      <text font-size="6.77333" x="327.838" y="323.044">
+        <tspan x="301" y="324.100">Use</tspan>
+        <tspan x="315" y="324.100" style="font-family: monospace">lastResort</tspan>
+        <tspan x="316" y="332.567">handler</tspan>
       </text>
     </g>
     <g>
       <polygon fill-rule="evenodd" points="320.041,35.7307 373.377,60.8536 320.041,85.9765 266.704,60.8536 " />
       <text font-size="6.77333" style="text-anchor: middle;" x="320.041" y="58.6741">
         <tspan x="320.041" y="58.6741">Handler enabled for</tspan>
-        <tspan x="320.041" y="67.1407">level of LogRecord?</tspan>
+        <tspan x="320.041" y="67.1407">level of record?</tspan>
       </text>
     </g>
     <g>
@@ -292,7 +305,7 @@
       <tspan x="323.75" y="99.0042">Yes</tspan>
     </text>
     <text font-size="6.77323" style="text-anchor: middle;" x="355.762" y="18.2449">
-      <tspan x="355.762" y="18.2449">LogRecord passed</tspan>
+      <tspan x="355.762" y="18.2449">Record passed</tspan>
       <tspan x="355.762" y="26.7116">to handler</tspan>
     </text>
     <line style="stroke-dasharray: 5" x1="330.96" y1="266.686" x2="377.733" y2="267.908" />