Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add darkmode support for difflib's comparison pages
  • Loading branch information
Wulian233 committed Feb 10, 2025
commit 8bc01413b68dfbe0c8d1a77c08c5d10ea54d7758
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,14 @@ 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 allow browsers to apply its default 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:#444}
.diff_add {background-color:darkgreen}
.diff_chg {background-color:goldenrod}
Comment thread
Wulian233 marked this conversation as resolved.
Outdated
.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:#444}
.diff_add {background-color:darkgreen}
.diff_chg {background-color:goldenrod}
.diff_sub {background-color:darkred}
}
</style>
</head>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Comparison pages with highlighted changes generated by the
:class:`difflib.HtmlDiff` class allow browsers to apply its default dark
mode.