Skip to content

Commit e642a24

Browse files
authored
gh-95953: Add a css class to changed lines of difflib.HtmlDiff make_table (#139226)
1 parent 72d5ee0 commit e642a24

File tree

4 files changed

+150
-144
lines changed

4 files changed

+150
-144
lines changed

Lib/difflib.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,8 +1924,11 @@ def _format_line(self,side,flag,linenum,text):
19241924
# make space non-breakable so they don't get compressed or line wrapped
19251925
text = text.replace(' ',' ').rstrip()
19261926

1927-
return '<td class="diff_header"%s>%s</td><td nowrap="nowrap">%s</td>' \
1928-
% (id,linenum,text)
1927+
# add a class to the td tag if there is a difference on the line
1928+
css_class = ' class="diff_changed" ' if flag else ' '
1929+
1930+
return f'<td class="diff_header"{id}>{linenum}</td>' \
1931+
+ f'<td{css_class}nowrap="nowrap">{text}</td>'
19291932

19301933
def _make_prefix(self):
19311934
"""Create unique anchor prefixes"""

0 commit comments

Comments
 (0)