diff --git a/Lib/difflib.py b/Lib/difflib.py index fedc85009aa03b..4a0600e4ebb01b 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 '%s%s' \ - % (id,linenum,text) + # add a class to the td tag if there is a difference on the line + css_class = ' class="diff_changed" ' if flag else ' ' + + return f'{linenum}' \ + + f'{text}' def _make_prefix(self): """Create unique anchor prefixes""" diff --git a/Lib/test/test_difflib_expect.html b/Lib/test/test_difflib_expect.html index 2346a6f9f8dddf..240e2c3336830a 100644 --- a/Lib/test/test_difflib_expect.html +++ b/Lib/test/test_difflib_expect.html @@ -59,11 +59,11 @@
from
to f1f1 - n2   1. Beautiful is beTTer than ugly.n2   1. Beautiful is better than ugly. - 3   2. Explicit is better than implicit. - 4   3. Simple is better than complex.3   3.   Simple is better than complex. - 5   4. Complex is better than complicated.4   4. Complicated is better than complex. - 5   5. Flat is better than nested. + n2   1. Beautiful is beTTer than ugly.n2   1. Beautiful is better than ugly. + 3   2. Explicit is better than implicit. + 4   3. Simple is better than complex.3   3.   Simple is better than complex. + 5   4. Complex is better than complicated.4   4. Complicated is better than complex. + 5   5. Flat is better than nested. 61236123 71237123 81238123 @@ -75,11 +75,11 @@ 1412314123 1512315123 1616 - n17   1. Beautiful is beTTer than ugly.n17   1. Beautiful is better than ugly. - 18   2. Explicit is better than implicit. - 19   3. Simple is better than complex.18   3.   Simple is better than complex. - 20   4. Complex is better than complicated.19   4. Complicated is better than complex. - 20   5. Flat is better than nested. + n17   1. Beautiful is beTTer than ugly.n17   1. Beautiful is better than ugly. + 18   2. Explicit is better than implicit. + 19   3. Simple is better than complex.18   3.   Simple is better than complex. + 20   4. Complex is better than complicated.19   4. Complicated is better than complex. + 20   5. Flat is better than nested. 2112321123 2212322123 2312323123 @@ -91,11 +91,11 @@ 2912329123 3012330123 3131 - t32   1. Beautiful is beTTer than ugly.t32   1. Beautiful is better than ugly. - 33   2. Explicit is better than implicit. - 34   3. Simple is better than complex.33   3.   Simple is better than complex. - 35   4. Complex is better than complicated.34   4. Complicated is better than complex. - 35   5. Flat is better than nested. + t32   1. Beautiful is beTTer than ugly.t32   1. Beautiful is better than ugly. + 33   2. Explicit is better than implicit. + 34   3. Simple is better than complex.33   3.   Simple is better than complex. + 35   4. Complex is better than complicated.34   4. Complicated is better than complex. + 35   5. Flat is better than nested. 3612336123 3712337123 3812338123 @@ -133,11 +133,11 @@

Context (first diff within numlines=5(default))


from
to f1f1 - n2   1. Beautiful is beTTer than ugly.n2   1. Beautiful is better than ugly. - 3   2. Explicit is better than implicit. - 4   3. Simple is better than complex.3   3.   Simple is better than complex. - 5   4. Complex is better than complicated.4   4. Complicated is better than complex. - 5   5. Flat is better than nested. + n2   1. Beautiful is beTTer than ugly.n2   1. Beautiful is better than ugly. + 3   2. Explicit is better than implicit. + 4   3. Simple is better than complex.3   3.   Simple is better than complex. + 5   4. Complex is better than complicated.4   4. Complicated is better than complex. + 5   5. Flat is better than nested. 61236123 71237123 81238123 @@ -150,11 +150,11 @@

Context (first diff within numlines=5(default))

1412314123 1512315123 1616 - n17   1. Beautiful is beTTer than ugly.n17   1. Beautiful is better than ugly. - 18   2. Explicit is better than implicit. - 19   3. Simple is better than complex.18   3.   Simple is better than complex. - 20   4. Complex is better than complicated.19   4. Complicated is better than complex. - 20   5. Flat is better than nested. + n17   1. Beautiful is beTTer than ugly.n17   1. Beautiful is better than ugly. + 18   2. Explicit is better than implicit. + 19   3. Simple is better than complex.18   3.   Simple is better than complex. + 20   4. Complex is better than complicated.19   4. Complicated is better than complex. + 20   5. Flat is better than nested. 2112321123 2212322123 2312323123 @@ -167,11 +167,11 @@

Context (first diff within numlines=5(default))

2912329123 3012330123 3131 - t32   1. Beautiful is beTTer than ugly.t32   1. Beautiful is better than ugly. - 33   2. Explicit is better than implicit. - 34   3. Simple is better than complex.33   3.   Simple is better than complex. - 35   4. Complex is better than complicated.34   4. Complicated is better than complex. - 35   5. Flat is better than nested. + t32   1. Beautiful is beTTer than ugly.t32   1. Beautiful is better than ugly. + 33   2. Explicit is better than implicit. + 34   3. Simple is better than complex.33   3.   Simple is better than complex. + 35   4. Complex is better than complicated.34   4. Complicated is better than complex. + 35   5. Flat is better than nested. 3612336123 3712337123 3812338123 @@ -192,11 +192,11 @@

Context (first diff after numlines=5(default))

94569456 1045610456 1111 - n12   1. Beautiful is beTTer than ugly.n12   1. Beautiful is better than ugly. - 13   2. Explicit is better than implicit. - 14   3. Simple is better than complex.13   3.   Simple is better than complex. - 15   4. Complex is better than complicated.14   4. Complicated is better than complex. - 15   5. Flat is better than nested. + n12   1. Beautiful is beTTer than ugly.n12   1. Beautiful is better than ugly. + 13   2. Explicit is better than implicit. + 14   3. Simple is better than complex.13   3.   Simple is better than complex. + 15   4. Complex is better than complicated.14   4. Complicated is better than complex. + 15   5. Flat is better than nested. 1612316123 1712317123 1812318123 @@ -209,11 +209,11 @@

Context (first diff after numlines=5(default))

2412324123 2512325123 2626 - n27   1. Beautiful is beTTer than ugly.n27   1. Beautiful is better than ugly. - 28   2. Explicit is better than implicit. - 29   3. Simple is better than complex.28   3.   Simple is better than complex. - 30   4. Complex is better than complicated.29   4. Complicated is better than complex. - 30   5. Flat is better than nested. + n27   1. Beautiful is beTTer than ugly.n27   1. Beautiful is better than ugly. + 28   2. Explicit is better than implicit. + 29   3. Simple is better than complex.28   3.   Simple is better than complex. + 30   4. Complex is better than complicated.29   4. Complicated is better than complex. + 30   5. Flat is better than nested. 3112331123 3212332123 3312333123 @@ -226,11 +226,11 @@

Context (first diff after numlines=5(default))

3912339123 4012340123 4141 - t42   1. Beautiful is beTTer than ugly.t42   1. Beautiful is better than ugly. - 43   2. Explicit is better than implicit. - 44   3. Simple is better than complex.43   3.   Simple is better than complex. - 45   4. Complex is better than complicated.44   4. Complicated is better than complex. - 45   5. Flat is better than nested. + t42   1. Beautiful is beTTer than ugly.t42   1. Beautiful is better than ugly. + 43   2. Explicit is better than implicit. + 44   3. Simple is better than complex.43   3.   Simple is better than complex. + 45   4. Complex is better than complicated.44   4. Complicated is better than complex. + 45   5. Flat is better than nested. 4612346123 4712347123 4812348123 @@ -247,11 +247,11 @@

Context (numlines=6)


from
to f1f1 - n2   1. Beautiful is beTTer than ugly.n2   1. Beautiful is better than ugly. - 3   2. Explicit is better than implicit. - 4   3. Simple is better than complex.3   3.   Simple is better than complex. - 5   4. Complex is better than complicated.4   4. Complicated is better than complex. - 5   5. Flat is better than nested. + n2   1. Beautiful is beTTer than ugly.n2   1. Beautiful is better than ugly. + 3   2. Explicit is better than implicit. + 4   3. Simple is better than complex.3   3.   Simple is better than complex. + 5   4. Complex is better than complicated.4   4. Complicated is better than complex. + 5   5. Flat is better than nested. 61236123 71237123 81238123 @@ -263,11 +263,11 @@

Context (numlines=6)

1412314123 1512315123 1616 - n17   1. Beautiful is beTTer than ugly.n17   1. Beautiful is better than ugly. - 18   2. Explicit is better than implicit. - 19   3. Simple is better than complex.18   3.   Simple is better than complex. - 20   4. Complex is better than complicated.19   4. Complicated is better than complex. - 20   5. Flat is better than nested. + n17   1. Beautiful is beTTer than ugly.n17   1. Beautiful is better than ugly. + 18   2. Explicit is better than implicit. + 19   3. Simple is better than complex.18   3.   Simple is better than complex. + 20   4. Complex is better than complicated.19   4. Complicated is better than complex. + 20   5. Flat is better than nested. 2112321123 2212322123 2312323123 @@ -279,11 +279,11 @@

Context (numlines=6)

2912329123 3012330123 3131 - t32   1. Beautiful is beTTer than ugly.t32   1. Beautiful is better than ugly. - 33   2. Explicit is better than implicit. - 34   3. Simple is better than complex.33   3.   Simple is better than complex. - 35   4. Complex is better than complicated.34   4. Complicated is better than complex. - 35   5. Flat is better than nested. + t32   1. Beautiful is beTTer than ugly.t32   1. Beautiful is better than ugly. + 33   2. Explicit is better than implicit. + 34   3. Simple is better than complex.33   3.   Simple is better than complex. + 35   4. Complex is better than complicated.34   4. Complicated is better than complex. + 35   5. Flat is better than nested. 3612336123 3712337123 3812338123 @@ -300,25 +300,25 @@

Context (numlines=0)


from
to - n2   1. Beautiful is beTTer than ugly.n2   1. Beautiful is better than ugly. - 3   2. Explicit is better than implicit. - 4   3. Simple is better than complex.3   3.   Simple is better than complex. - 5   4. Complex is better than complicated.4   4. Complicated is better than complex. - 5   5. Flat is better than nested. + n2   1. Beautiful is beTTer than ugly.n2   1. Beautiful is better than ugly. + 3   2. Explicit is better than implicit. + 4   3. Simple is better than complex.3   3.   Simple is better than complex. + 5   4. Complex is better than complicated.4   4. Complicated is better than complex. + 5   5. Flat is better than nested. - n17   1. Beautiful is beTTer than ugly.n17   1. Beautiful is better than ugly. - 18   2. Explicit is better than implicit. - 19   3. Simple is better than complex.18   3.   Simple is better than complex. - 20   4. Complex is better than complicated.19   4. Complicated is better than complex. - 20   5. Flat is better than nested. + n17   1. Beautiful is beTTer than ugly.n17   1. Beautiful is better than ugly. + 18   2. Explicit is better than implicit. + 19   3. Simple is better than complex.18   3.   Simple is better than complex. + 20   4. Complex is better than complicated.19   4. Complicated is better than complex. + 20   5. Flat is better than nested. - t32   1. Beautiful is beTTer than ugly.t32   1. Beautiful is better than ugly. - 33   2. Explicit is better than implicit. - 34   3. Simple is better than complex.33   3.   Simple is better than complex. - 35   4. Complex is better than complicated.34   4. Complicated is better than complex. - 35   5. Flat is better than nested. + t32   1. Beautiful is beTTer than ugly.t32   1. Beautiful is better than ugly. + 33   2. Explicit is better than implicit. + 34   3. Simple is better than complex.33   3.   Simple is better than complex. + 35   4. Complex is better than complicated.34   4. Complicated is better than complex. + 35   5. Flat is better than nested.

Same Context

@@ -418,11 +418,11 @@

tabsize=2

f1f1 - t2    Line 1: preceded by from:[tt] to:[ssss]t2    Line 1: preceded by from:[tt] to:[ssss] - 3      Line 2: preceded by from:[sstt] to:[sssst]3      Line 2: preceded by from:[sstt] to:[sssst] - 4      Line 3: preceded by from:[sstst] to:[ssssss]4      Line 3: preceded by from:[sstst] to:[ssssss] - 5Line 4:   has from:[sst] to:[sss] after :5Line 4:   has from:[sst] to:[sss] after : - 6Line 5: has from:[t] to:[ss] at end 6Line 5: has from:[t] to:[ss] at end + t2    Line 1: preceded by from:[tt] to:[ssss]t2    Line 1: preceded by from:[tt] to:[ssss] + 3      Line 2: preceded by from:[sstt] to:[sssst]3      Line 2: preceded by from:[sstt] to:[sssst] + 4      Line 3: preceded by from:[sstst] to:[ssssss]4      Line 3: preceded by from:[sstst] to:[ssssss] + 5Line 4:   has from:[sst] to:[sss] after :5Line 4:   has from:[sst] to:[sss] after : + 6Line 5: has from:[t] to:[ss] at end 6Line 5: has from:[t] to:[ss] at end

tabsize=default

@@ -434,11 +434,11 @@

tabsize=default

f1f1 - t2                Line 1: preceded by from:[tt] to:[ssss]t2    Line 1: preceded by from:[tt] to:[ssss] - 3                Line 2: preceded by from:[sstt] to:[sssst]3        Line 2: preceded by from:[sstt] to:[sssst] - 4                Line 3: preceded by from:[sstst] to:[ssssss]4      Line 3: preceded by from:[sstst] to:[ssssss] - 5Line 4:         has from:[sst] to:[sss] after :5Line 4:   has from:[sst] to:[sss] after : - 6Line 5: has from:[t] to:[ss] at end     6Line 5: has from:[t] to:[ss] at end + t2                Line 1: preceded by from:[tt] to:[ssss]t2    Line 1: preceded by from:[tt] to:[ssss] + 3                Line 2: preceded by from:[sstt] to:[sssst]3        Line 2: preceded by from:[sstt] to:[sssst] + 4                Line 3: preceded by from:[sstst] to:[ssssss]4      Line 3: preceded by from:[sstst] to:[ssssss] + 5Line 4:         has from:[sst] to:[sss] after :5Line 4:   has from:[sst] to:[sss] after : + 6Line 5: has from:[t] to:[ss] at end     6Line 5: has from:[t] to:[ss] at end

Context (wrapcolumn=14,numlines=0)

@@ -449,31 +449,31 @@

Context (wrapcolumn=14,numlines=0)

- n4line 2n4line 2    adde -  >d + n4line 2n4line 2    adde +  >d - n6line 4   changn6line 4   chanG - >ed>Ed - 7line 5   chang7line 5a  chanG - >ed>ed - 8line 6   chang8line 6a  chang - >ed>Ed + n6line 4   changn6line 4   chanG + >ed>Ed + 7line 5   chang7line 5a  chanG + >ed>ed + 8line 6   chang8line 6a  chang + >ed>Ed - n10line 8  subtran10line 8 - >cted  + n10line 8  subtran10line 8 + >cted  - t1212345678901234t121234567890 - >56789012345689  - >012345  - 13short line13another long l -  >ine that needs -  > to be wrapped - 14just fits in!!14just fitS in!! - 15just fits in t15just fits in t - >wo lines yup!!>wo lineS yup!! + t1212345678901234t121234567890 + >56789012345689  + >012345  + 13short line13another long l +  >ine that needs +  > to be wrapped + 14just fits in!!14just fitS in!! + 15just fits in t15just fits in t + >wo lines yup!!>wo lineS yup!!

wrapcolumn=14,splitlines()

@@ -489,28 +489,28 @@

wrapcolumn=14,splitlines()

>56789012345689>56789012345689 >012345>012345 3line 13line 1 - n4line 2n4line 2    adde -  >d + n4line 2n4line 2    adde +  >d 5line 35line 3 - n6line 4   changn6line 4   chanG - >ed>Ed - 7line 5   chang7line 5a  chanG - >ed>ed - 8line 6   chang8line 6a  chang - >ed>Ed + n6line 4   changn6line 4   chanG + >ed>Ed + 7line 5   chang7line 5a  chanG + >ed>ed + 8line 6   chang8line 6a  chang + >ed>Ed 9line 79line 7 - n10line 8  subtran10line 8 - >cted  + n10line 8  subtran10line 8 + >cted  11line 911line 9 - t1212345678901234t121234567890 - >56789012345689  - >012345  - 13short line13another long l -  >ine that needs -  > to be wrapped - 14just fits in!!14just fitS in!! - 15just fits in t15just fits in t - >wo lines yup!!>wo lineS yup!! + t1212345678901234t121234567890 + >56789012345689  + >012345  + 13short line13another long l +  >ine that needs +  > to be wrapped + 14just fits in!!14just fitS in!! + 15just fits in t15just fits in t + >wo lines yup!!>wo lineS yup!! 16the end16the end @@ -527,28 +527,28 @@

wrapcolumn=14,splitlines(True)

>56789012345689>56789012345689 >012345>012345 3line 13line 1 - n4line 2n4line 2    adde -  >d + n4line 2n4line 2    adde +  >d 5line 35line 3 - n6line 4   changn6line 4   chanG - >ed>Ed - 7line 5   chang7line 5a  chanG - >ed>ed - 8line 6   chang8line 6a  chang - >ed>Ed + n6line 4   changn6line 4   chanG + >ed>Ed + 7line 5   chang7line 5a  chanG + >ed>ed + 8line 6   chang8line 6a  chang + >ed>Ed 9line 79line 7 - n10line 8  subtran10line 8 - >cted  + n10line 8  subtran10line 8 + >cted  11line 911line 9 - t1212345678901234t121234567890 - >56789012345689  - >012345  - 13short line13another long l -  >ine that needs -  > to be wrapped - 14just fits in!!14just fitS in!! - 15just fits in t15just fits in t - >wo lines yup!!>wo lineS yup!! + t1212345678901234t121234567890 + >56789012345689  + >012345  + 13short line13another long l +  >ine that needs +  > to be wrapped + 14just fits in!!14just fitS in!! + 15just fits in t15just fits in t + >wo lines yup!!>wo lineS yup!! 16the end16the end diff --git a/Misc/ACKS b/Misc/ACKS index c54a27bbc8eb0b..0812b229e0ada4 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -622,6 +622,7 @@ Soumendra Ganguly (गङ्गोपाध्याय) Fred Gansevles Paul Ganssle Tian Gao +Katie Gardner Lars Marius Garshol Jake Garver Dan Gass diff --git a/Misc/NEWS.d/next/Library/2025-09-22-11-19-05.gh-issue-95953.7oLoag.rst b/Misc/NEWS.d/next/Library/2025-09-22-11-19-05.gh-issue-95953.7oLoag.rst new file mode 100644 index 00000000000000..27a8f837dda392 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-09-22-11-19-05.gh-issue-95953.7oLoag.rst @@ -0,0 +1,2 @@ +A CSS class, ``diff_changed``, was added to the changed lines in the +``make_table`` output of :class:`difflib.HtmlDiff`. Patch by Katie Gardner.