Skip to content

Add a CSS class to identify changed cells in difflib.HtmlDiff output #95953

Closed

Description

@kesara

Feature or enhancement

The current output of make_table method in difflib.HtmlDiff, doesn't add a CSS class when the content in a cell is changed.

Sample input:

from difflib import HtmlDiff
diff = HtmlDiff()
fromlines = "f oo bar"
tolines = "f 00 bar"
diff.make_table(fromlines, tolines)

Current output:

<tr>
  <td class="diff_next"><a href="#difflib_chg_to0__top">t</a></td>
  <td class="diff_header" id="from0_2">2</td>
  <td nowrap="nowrap">f&nbsp;<span class="diff_chg">oo</span>&nbsp;bar</td>
  <td class="diff_next"><a href="#difflib_chg_to0__top">t</a></td>
  <td class="diff_header" id="to0_2">2</td>
  <td nowrap="nowrap">f&nbsp;<span class="diff_chg">00</span>&nbsp;bar</td>
</tr>

Add a new class (for example, diff_changed) to the 3rd and 6th cells when they have changed content.

Proposed output:

<tr>
  <td class="diff_next"><a href="#difflib_chg_to0__top">t</a></td>
  <td class="diff_header" id="from0_2">2</td>
  <td class="diff_changed" nowrap="nowrap">f&nbsp;<span class="diff_chg">oo</span>&nbsp;bar</td>
  <td class="diff_next"><a href="#difflib_chg_to0__top">t</a></td>
  <td class="diff_header" id="to0_2">2</td>
  <td class="diff_changed" nowrap="nowrap">f&nbsp;<span class="diff_chg">00</span>&nbsp;bar</td>
</tr>

Pitch

This will allow more customizations to be done for applications that make use of this library.
For example, when required whole line can have a background colour when content is changed.

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 27, 2023
  2. added 6 commits that reference this issue on Sep 22, 2025
  3. added a commit that references this issue on Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions