Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,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
---

Expand Down
13 changes: 11 additions & 2 deletions Lib/difflib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion Lib/test/test_difflib_expect.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparison pages with highlighted changes generated by the
:class:`difflib.HtmlDiff` class now support dark mode.
Loading