Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
25 changes: 16 additions & 9 deletions Lib/difflib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,15 +1612,13 @@ def _line_pair_iterator():


_file_template = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=%(charset)s" />
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="%(charset)s">
<title>Comparison page</title>
<style type="text/css">%(styles)s
</style>
</head>
Expand All @@ -1632,13 +1630,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
23 changes: 15 additions & 8 deletions Lib/test/test_difflib_expect.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<title>Comparison page</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