From 12bd15f7b378879ed7971d14a4388cd9a38a14dc Mon Sep 17 00:00:00 2001 From: Wulian233 <1055917385@qq.com> Date: Tue, 11 Feb 2025 16:58:57 +0800 Subject: [PATCH] gh-129939: Add darkmode support for difflib's comparison pages (#129940) --- Doc/whatsnew/3.14.rst | 7 +++++++ Lib/difflib.py | 13 +++++++++++-- Lib/test/test_difflib_expect.html | 11 ++++++++++- .../2025-02-10-14-34-34.gh-issue-129939.B08L4e.rst | 2 ++ 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-02-10-14-34-34.gh-issue-129939.B08L4e.rst diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 8dac88ecb2ff..3c7cc1b4529d 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -411,6 +411,13 @@ decimal :meth:`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 7f595b6c72e6..c124afdd0395 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -1632,13 +1632,22 @@ _file_template = """ """ _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 = """ 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 000000000000..5014f5bc3c7f --- /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. -- 2.47.3