KEMBAR78
Add a CSS class to identify changed cells in difflib.HtmlDiff output · Issue #95953 · python/cpython · GitHub
Skip to content

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

@kesara

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

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