gh-134580: Modernizing `difflib.HtmlDiff` for HTML Output (#134581) · python/cpython@7ca6d79

GitHub

@@ -1615,16 +1615,13 @@ def _line_pair_iterator():

161516151616161616171617_file_template="""

1618-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

1619- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

1620-1621-<html>

1622-1618+<!DOCTYPE html>

1619+<html lang="en">

16231620<head>

1624- <meta http-equiv="Content-Type"

1625-content="text/html; charset=%(charset)s" />

1626- <title></title>

1627- <style type="text/css">%(styles)s

1621+ <meta charset="%(charset)s">

1622+<meta name="viewport" content="width=device-width, initial-scale=1">

1623+ <title>Diff comparison</title>

1624+ <style>%(styles)s

16281625 </style>

16291626</head>

16301627@@ -1636,20 +1633,45 @@ def _line_pair_iterator():

1636163316371634_styles="""

16381635 :root {color-scheme: light dark}

1639- table.diff {font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace; border:medium}

1640- .diff_header {background-color:#e0e0e0}

1641- td.diff_header {text-align:right}

1642- .diff_next {background-color:#c0c0c0}

1636+ table.diff {

1637+ font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace;

1638+ border: medium;

1639+ }

1640+ .diff_header {

1641+ background-color: #e0e0e0;

1642+ font-weight: bold;

1643+ }

1644+ td.diff_header {

1645+ text-align: right;

1646+ padding: 0 8px;

1647+ }

1648+ .diff_next {

1649+ background-color: #c0c0c0;

1650+ padding: 4px 0;

1651+ }

16431652 .diff_add {background-color:palegreen}

16441653 .diff_chg {background-color:#ffff77}

16451654 .diff_sub {background-color:#ffaaaa}

1655+ table.diff[summary="Legends"] {

1656+ margin-top: 20px;

1657+ border: 1px solid #ccc;

1658+ }

1659+ table.diff[summary="Legends"] th {

1660+ background-color: #e0e0e0;

1661+ padding: 4px 8px;

1662+ }

1663+ table.diff[summary="Legends"] td {

1664+ padding: 4px 8px;

1665+ }

1646166616471667 @media (prefers-color-scheme: dark) {

16481668 .diff_header {background-color:#666}

16491669 .diff_next {background-color:#393939}

16501670 .diff_add {background-color:darkgreen}

16511671 .diff_chg {background-color:#847415}

16521672 .diff_sub {background-color:darkred}

1673+ table.diff[summary="Legends"] {border-color:#555}

1674+ table.diff[summary="Legends"] th{background-color:#666}

16531675 }"""

1654167616551677_table_template="""

@@ -1692,7 +1714,7 @@ class HtmlDiff(object):

16921714 make_table -- generates HTML for a single side by side table

16931715 make_file -- generates complete HTML file with a single side by side table

169417161695- See tools/scripts/diff.py for an example usage of this class.

1717+ See Doc/includes/diff.py for an example usage of this class.

16961718 """

1697171916981720_file_template=_file_template