]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-129939: Add darkmode support for difflib's comparison pages (#129940)
authorWulian233 <1055917385@qq.com>
Tue, 11 Feb 2025 08:58:57 +0000 (16:58 +0800)
committerGitHub <noreply@github.com>
Tue, 11 Feb 2025 08:58:57 +0000 (10:58 +0200)
Doc/whatsnew/3.14.rst
Lib/difflib.py
Lib/test/test_difflib_expect.html
Misc/NEWS.d/next/Library/2025-02-10-14-34-34.gh-issue-129939.B08L4e.rst [new file with mode: 0644]

index 8dac88ecb2ff649b2af85d777dbda1d33fe504eb..3c7cc1b4529d32262b597adfbee4f6f24158037a 100644 (file)
@@ -411,6 +411,13 @@ decimal
   :meth:`Decimal.from_number() <decimal.Decimal.from_number>`.
   (Contributed by Serhiy Storchaka in :gh:`121798`.)
 
+difflib
+-------
+
+* Comparison pages with highlighted changes generated by the
+  :class:`difflib.HtmlDiff` class now support dark mode.
+  (Contributed by Jiahao Li in :gh:`129939`.)
+
 dis
 ---
 
index 7f595b6c72e641df6aa5cf18b0d2093f72992a56..c124afdd0395597d42debd320fb04dcb97b55f94 100644 (file)
@@ -1632,13 +1632,22 @@ _file_template = """
 </html>"""
 
 _styles = """
+        :root {color-scheme: light dark}
         table.diff {font-family:Courier; border:medium;}
         .diff_header {background-color:#e0e0e0}
         td.diff_header {text-align:right}
         .diff_next {background-color:#c0c0c0}
-        .diff_add {background-color:#aaffaa}
+        .diff_add {background-color:palegreen}
         .diff_chg {background-color:#ffff77}
-        .diff_sub {background-color:#ffaaaa}"""
+        .diff_sub {background-color:#ffaaaa}
+
+        @media (prefers-color-scheme: dark) {
+            .diff_header {background-color:#666}
+            .diff_next {background-color:#393939}
+            .diff_add {background-color:darkgreen}
+            .diff_chg {background-color:#847415}
+            .diff_sub {background-color:darkred}
+        }"""
 
 _table_template = """
     <table class="diff" id="difflib_chg_%(prefix)s_top"
index 3e6a7b7a9933d68b2aca2bd390a50b26442312e5..6c2ee49837e68917fd0b161da096242b4538d0d3 100644 (file)
@@ -9,13 +9,22 @@
           content="text/html; charset=utf-8" />
     <title></title>
     <style type="text/css">
+        :root {color-scheme: light dark}
         table.diff {font-family:Courier; border:medium;}
         .diff_header {background-color:#e0e0e0}
         td.diff_header {text-align:right}
         .diff_next {background-color:#c0c0c0}
-        .diff_add {background-color:#aaffaa}
+        .diff_add {background-color:palegreen}
         .diff_chg {background-color:#ffff77}
         .diff_sub {background-color:#ffaaaa}
+
+        @media (prefers-color-scheme: dark) {
+            .diff_header {background-color:#666}
+            .diff_next {background-color:#393939}
+            .diff_add {background-color:darkgreen}
+            .diff_chg {background-color:#847415}
+            .diff_sub {background-color:darkred}
+        }
     </style>
 </head>
 
diff --git a/Misc/NEWS.d/next/Library/2025-02-10-14-34-34.gh-issue-129939.B08L4e.rst b/Misc/NEWS.d/next/Library/2025-02-10-14-34-34.gh-issue-129939.B08L4e.rst
new file mode 100644 (file)
index 0000000..5014f5b
--- /dev/null
@@ -0,0 +1,2 @@
+Comparison pages with highlighted changes generated by the
+:class:`difflib.HtmlDiff` class now support dark mode.