https://github.com/python/cpython/commit/12bd15f7b378879ed7971d14a4388cd9a38a14dc
commit: 12bd15f7b378879ed7971d14a4388cd9a38a14dc
branch: main
author: Wulian233 <[email protected]>
committer: hugovk <[email protected]>
date: 2025-02-11T10:58:57+02:00
summary:
gh-129939: Add darkmode support for difflib's comparison pages (#129940)
files:
A Misc/NEWS.d/next/Library/2025-02-10-14-34-34.gh-issue-129939.B08L4e.rst
M Doc/whatsnew/3.14.rst
M Lib/difflib.py
M Lib/test/test_difflib_expect.html
diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst
index 8dac88ecb2ff64..3c7cc1b4529d32 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -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
---
diff --git a/Lib/difflib.py b/Lib/difflib.py
index 7f595b6c72e641..c124afdd039559 100644
--- a/Lib/difflib.py
+++ b/Lib/difflib.py
@@ -1632,13 +1632,22 @@ def _line_pair_iterator():
</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"
diff --git a/Lib/test/test_difflib_expect.html
b/Lib/test/test_difflib_expect.html
index 3e6a7b7a9933d6..6c2ee49837e689 100644
--- a/Lib/test/test_difflib_expect.html
+++ b/Lib/test/test_difflib_expect.html
@@ -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
index 00000000000000..5014f5bc3c7f3c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-02-10-14-34-34.gh-issue-129939.B08L4e.rst
@@ -0,0 +1,2 @@
+Comparison pages with highlighted changes generated by the
+:class:`difflib.HtmlDiff` class now support dark mode.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]