From 9037f264650db1a66f80b4974b877cfca84f71fd Mon Sep 17 00:00:00 2001
From: Katie <5213160+KatieLG@users.noreply.github.com>
Date: Mon, 22 Sep 2025 11:01:12 +0100
Subject: [PATCH 1/4] gh-95953: add a css class to changed lines of
difflib.HtmlDiff make_table
---
Lib/difflib.py | 7 +-
Lib/test/test_difflib_expect.html | 284 +++++++++---------
...5-09-22-11-19-05.gh-issue-95953.7oLoag.rst | 2 +
3 files changed, 149 insertions(+), 144 deletions(-)
create mode 100644 Misc/NEWS.d/next/Library/2025-09-22-11-19-05.gh-issue-95953.7oLoag.rst
diff --git a/Lib/difflib.py b/Lib/difflib.py
index fedc85009aa03b..833530c255437c 100644
--- a/Lib/difflib.py
+++ b/Lib/difflib.py
@@ -1924,8 +1924,11 @@ def _format_line(self,side,flag,linenum,text):
# make space non-breakable so they don't get compressed or line wrapped
text = text.replace(' ',' ').rstrip()
- return '
f | | f | |
- n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
- | 2. Explicit is better than implicit. | | |
- | 3. Simple is better than complex. | | 3. Simple is better than complex. |
- | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
- | | | 5. Flat is better than nested. |
+ n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
+ | 2. Explicit is better than implicit. | | |
+ | 3. Simple is better than complex. | | 3. Simple is better than complex. |
+ | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
+ | | | 5. Flat is better than nested. |
| 123 | | 123 |
| 123 | | 123 |
| 123 | | 123 |
@@ -75,11 +75,11 @@
| 123 | | 123 |
| 123 | | 123 |
| | | |
- n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
- | 2. Explicit is better than implicit. | | |
- | 3. Simple is better than complex. | | 3. Simple is better than complex. |
- | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
- | | | 5. Flat is better than nested. |
+ n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
+ | 2. Explicit is better than implicit. | | |
+ | 3. Simple is better than complex. | | 3. Simple is better than complex. |
+ | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
+ | | | 5. Flat is better than nested. |
| 123 | | 123 |
| 123 | | 123 |
| 123 | | 123 |
@@ -91,11 +91,11 @@
| 123 | | 123 |
| 123 | | 123 |
| | | |
- t | 1. Beautiful is beTTer than ugly. | t | 1. Beautiful is better than ugly. |
- | 2. Explicit is better than implicit. | | |
- | 3. Simple is better than complex. | | 3. Simple is better than complex. |
- | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
- | | | 5. Flat is better than nested. |
+ t | 1. Beautiful is beTTer than ugly. | t | 1. Beautiful is better than ugly. |
+ | 2. Explicit is better than implicit. | | |
+ | 3. Simple is better than complex. | | 3. Simple is better than complex. |
+ | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
+ | | | 5. Flat is better than nested. |
| 123 | | 123 |
| 123 | | 123 |
| 123 | | 123 |
@@ -133,11 +133,11 @@ Context (first diff within numlines=5(default))
|
|
f | | f | |
- n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
- | 2. Explicit is better than implicit. | | |
- | 3. Simple is better than complex. | | 3. Simple is better than complex. |
- | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
- | | | 5. Flat is better than nested. |
+ n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
+ | 2. Explicit is better than implicit. | | |
+ | 3. Simple is better than complex. | | 3. Simple is better than complex. |
+ | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
+ | | | 5. Flat is better than nested. |
| 123 | | 123 |
| 123 | | 123 |
| 123 | | 123 |
@@ -150,11 +150,11 @@ Context (first diff within numlines=5(default))
| 123 | | 123 |
| 123 | | 123 |
| | | |
- n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
- | 2. Explicit is better than implicit. | | |
- | 3. Simple is better than complex. | | 3. Simple is better than complex. |
- | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
- | | | 5. Flat is better than nested. |
+ n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
+ | 2. Explicit is better than implicit. | | |
+ | 3. Simple is better than complex. | | 3. Simple is better than complex. |
+ | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
+ | | | 5. Flat is better than nested. |
| 123 | | 123 |
| 123 | | 123 |
| 123 | | 123 |
@@ -167,11 +167,11 @@ Context (first diff within numlines=5(default))
| 123 | | 123 |
| 123 | | 123 |
| | | |
- t | 1. Beautiful is beTTer than ugly. | t | 1. Beautiful is better than ugly. |
- | 2. Explicit is better than implicit. | | |
- | 3. Simple is better than complex. | | 3. Simple is better than complex. |
- | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
- | | | 5. Flat is better than nested. |
+ t | 1. Beautiful is beTTer than ugly. | t | 1. Beautiful is better than ugly. |
+ | 2. Explicit is better than implicit. | | |
+ | 3. Simple is better than complex. | | 3. Simple is better than complex. |
+ | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
+ | | | 5. Flat is better than nested. |
| 123 | | 123 |
| 123 | | 123 |
| 123 | | 123 |
@@ -192,11 +192,11 @@ Context (first diff after numlines=5(default))
| 456 | | 456 |
| 456 | | 456 |
| | | |
- n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
- | 2. Explicit is better than implicit. | | |
- | 3. Simple is better than complex. | | 3. Simple is better than complex. |
- | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
- | | | 5. Flat is better than nested. |
+ n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
+ | 2. Explicit is better than implicit. | | |
+ | 3. Simple is better than complex. | | 3. Simple is better than complex. |
+ | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
+ | | | 5. Flat is better than nested. |
| 123 | | 123 |
| 123 | | 123 |
| 123 | | 123 |
@@ -209,11 +209,11 @@ Context (first diff after numlines=5(default))
| 123 | | 123 |
| 123 | | 123 |
| | | |
- n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
- | 2. Explicit is better than implicit. | | |
- | 3. Simple is better than complex. | | 3. Simple is better than complex. |
- | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
- | | | 5. Flat is better than nested. |
+ n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
+ | 2. Explicit is better than implicit. | | |
+ | 3. Simple is better than complex. | | 3. Simple is better than complex. |
+ | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
+ | | | 5. Flat is better than nested. |
| 123 | | 123 |
| 123 | | 123 |
| 123 | | 123 |
@@ -226,11 +226,11 @@ Context (first diff after numlines=5(default))
| 123 | | 123 |
| 123 | | 123 |
| | | |
- t | 1. Beautiful is beTTer than ugly. | t | 1. Beautiful is better than ugly. |
- | 2. Explicit is better than implicit. | | |
- | 3. Simple is better than complex. | | 3. Simple is better than complex. |
- | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
- | | | 5. Flat is better than nested. |
+ t | 1. Beautiful is beTTer than ugly. | t | 1. Beautiful is better than ugly. |
+ | 2. Explicit is better than implicit. | | |
+ | 3. Simple is better than complex. | | 3. Simple is better than complex. |
+ | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
+ | | | 5. Flat is better than nested. |
| 123 | | 123 |
| 123 | | 123 |
| 123 | | 123 |
@@ -247,11 +247,11 @@ Context (numlines=6)
|
|
f | | f | |
- n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
- | 2. Explicit is better than implicit. | | |
- | 3. Simple is better than complex. | | 3. Simple is better than complex. |
- | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
- | | | 5. Flat is better than nested. |
+ n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
+ | 2. Explicit is better than implicit. | | |
+ | 3. Simple is better than complex. | | 3. Simple is better than complex. |
+ | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
+ | | | 5. Flat is better than nested. |
| 123 | | 123 |
| 123 | | 123 |
| 123 | | 123 |
@@ -263,11 +263,11 @@ Context (numlines=6)
| 123 | | 123 |
| 123 | | 123 |
| | | |
- n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
- | 2. Explicit is better than implicit. | | |
- | 3. Simple is better than complex. | | 3. Simple is better than complex. |
- | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
- | | | 5. Flat is better than nested. |
+ n | 1. Beautiful is beTTer than ugly. | n | 1. Beautiful is better than ugly. |
+ | 2. Explicit is better than implicit. | | |
+ | 3. Simple is better than complex. | | 3. Simple is better than complex. |
+ | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
+ | | | 5. Flat is better than nested. |
| 123 | | 123 |
| 123 | | 123 |
| 123 | | 123 |
@@ -279,11 +279,11 @@ Context (numlines=6)
| 123 | | 123 |
| 123 | | 123 |
| | | |
- t | 1. Beautiful is beTTer than ugly. | t | 1. Beautiful is better than ugly. |
- | 2. Explicit is better than implicit. | | |
- | 3. Simple is better than complex. | | 3. Simple is better than complex. |
- | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
- | | | 5. Flat is better than nested. |
+ t | 1. Beautiful is beTTer than ugly. | t | 1. Beautiful is better than ugly. |
+ | 2. Explicit is better than implicit. | | |
+ | 3. Simple is better than complex. | | 3. Simple is better than complex. |
+ | 4. Complex is better than complicated. | | 4. Complicated is better than complex. |
+ | | | 5. Flat is better than nested. |
| 123 | | 123 |
| 123 | | 123 |
| 123 | | 123 |
@@ -300,25 +300,25 @@ Context (numlines=0)
|
|
f | | f | |
- t | Line 1: preceded by from:[tt] to:[ssss] | t | Line 1: preceded by from:[tt] to:[ssss] |
- | Line 2: preceded by from:[sstt] to:[sssst] | | Line 2: preceded by from:[sstt] to:[sssst] |
- | Line 3: preceded by from:[sstst] to:[ssssss] | | Line 3: preceded by from:[sstst] to:[ssssss] |
- | Line 4: has from:[sst] to:[sss] after : | | Line 4: has from:[sst] to:[sss] after : |
- | Line 5: has from:[t] to:[ss] at end | | Line 5: has from:[t] to:[ss] at end |
+ t | Line 1: preceded by from:[tt] to:[ssss] | t | Line 1: preceded by from:[tt] to:[ssss] |
+ | Line 2: preceded by from:[sstt] to:[sssst] | | Line 2: preceded by from:[sstt] to:[sssst] |
+ | Line 3: preceded by from:[sstst] to:[ssssss] | | Line 3: preceded by from:[sstst] to:[ssssss] |
+ | Line 4: has from:[sst] to:[sss] after : | | Line 4: has from:[sst] to:[sss] after : |
+ | Line 5: has from:[t] to:[ss] at end | | Line 5: has from:[t] to:[ss] at end |
f | | f | |
- t | Line 1: preceded by from:[tt] to:[ssss] | t | Line 1: preceded by from:[tt] to:[ssss] |
- | Line 2: preceded by from:[sstt] to:[sssst] | | Line 2: preceded by from:[sstt] to:[sssst] |
- | Line 3: preceded by from:[sstst] to:[ssssss] | | Line 3: preceded by from:[sstst] to:[ssssss] |
- | Line 4: has from:[sst] to:[sss] after : | | Line 4: has from:[sst] to:[sss] after : |
- | Line 5: has from:[t] to:[ss] at end | | Line 5: has from:[t] to:[ss] at end |
+ t | Line 1: preceded by from:[tt] to:[ssss] | t | Line 1: preceded by from:[tt] to:[ssss] |
+ | Line 2: preceded by from:[sstt] to:[sssst] | | Line 2: preceded by from:[sstt] to:[sssst] |
+ | Line 3: preceded by from:[sstst] to:[ssssss] | | Line 3: preceded by from:[sstst] to:[ssssss] |
+ | Line 4: has from:[sst] to:[sss] after : | | Line 4: has from:[sst] to:[sss] after : |
+ | Line 5: has from:[t] to:[ss] at end | | Line 5: has from:[t] to:[ss] at end |