From: Wulian233 <1055917385@qq.com> Date: Tue, 11 Feb 2025 08:58:57 +0000 (+0800) Subject: gh-129939: Add darkmode support for difflib's comparison pages (#129940) X-Git-Tag: v3.14.0a5~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12bd15f7b378879ed7971d14a4388cd9a38a14dc;p=thirdparty%2FPython%2Fcpython.git gh-129939: Add darkmode support for difflib's comparison pages (#129940) --- 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.