diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 23b1f5f2e0c67c..63f56189412794 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -410,6 +410,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 7f595b6c72e641..c124afdd039559 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -1632,13 +1632,22 @@ def _line_pair_iterator(): """ _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 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.