GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Modernizing `difflib.HtmlDiff` for HTML Output · Issue #134580 · python/cpython

Modernizing difflib.HtmlDiff for HTML Output #134580

New issue
Copy link
New issue
Copy link
Closed
Closed
Modernizing difflib.HtmlDiff for HTML Output#134580
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@Wulian233
Wulian233
opened on May 23, 2025
Issue body actions

Feature or enhancement

Proposal:

Previously, I added dark mode support to the HTML export feature of difflib, and during that process, I uncovered several issues.

By opening the browser's developer tools (F12) and inspecting the generated HTML, you can observe a number of warnings, such as:

Image

I initially addressed these warnings in the same pull request that added dark mode support. However, we later decided it would be better to split these changes into a separate PR—each PR should serve a single purpose. As a result, the warning fixes were rolled back from that submission. (see #129940 (comment))

Recently, I resumed working on this issue. I discovered that a large portion of these browser warnings stem from the legacy nature of the generated HTML. For example, the first line of the html still uses:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

And elements like:

<meta http-equiv="Content-Type"
      content="text/html; charset=%(charset)s" />

These are artifacts from the HTML4 era—a specification that was finalized more than two decades ago. While HTML5 remains backward-compatible with this syntax, I believe updating to modern HTML5 conventions is the right move. In 2025, there's no need to worry about browsers lacking HTML5 support.

For instance, HTML5 removes the need for lengthy DTD declarations (see here), simplifying the doctype to just <!DOCTYPE html>. This also makes the resulting HTML cleaner and easier to maintain.

With that in mind, I’m proposing to modernize difflib.HtmlDiff, not just updating the HTML structure to HTML5, but also refining the CSS for improved styling.

Take the current layout, for example: it’s not easy to distinguish line numbers from content maybe it's not very user-friendly.

Image

In the revised version, the diff content has been slightly enlarged for better readability. Line numbers are bolded and given more horizontal space, preventing them from blending into the content and causing visual confusion.

Image

Additionally, the legend section has been visually enhanced—now more intuitive and aesthetically pleasing. And, of course, all browser warnings have been eliminated!

Before: Image
After: Image

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-134580: Modernizing difflib.HtmlDiff for HTML Output #134581
Reacted by Michael Scott Asato Cuthbert
Reacted by Michael Scott Asato Cuthbert and Wulian233

Activity

  1. Wulian233
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on May 23, 2025
  2. hugovk
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on May 23, 2025
  3. hugovk
    added a commit that references this issue on May 28, 2025

    gh-134580: Modernizing `difflib.HtmlDiff` for HTML Output (#134581)

    7ca6d79
  4. hugovk
    closed this as completedon May 28, 2025
  5. Pranjal095
    added a commit that references this issue on Jul 12, 2025

    pythongh-134580: Modernizing `difflib.HtmlDiff` for HTML Output (pyth…

    985c156
  6. mscuthbert commented on Jul 15, 2025

    @mscuthbert
    mscuthbert
    on Jul 15, 2025
    More actions

    Thank you @Wulian233 for bringing this important tool to the present!

    Reacted by Hugo van Kemenade and Wulian233
  7. taegyunkim
    added a commit that references this issue on Aug 4, 2025

    pythongh-134580: Modernizing `difflib.HtmlDiff` for HTML Output (pyth…

    dda6c8d
  8. StanFromIreland
    marked Modernize HTML output of difflib.HtmlDiff.make_file() #67852 as a duplicate of this issue on Sep 7, 2025
  9. gostak-dd
    added a commit that references this issue on Jun 2, 2026

    pythongh-134580: Modernizing `difflib.HtmlDiff` for HTML Output (pyth…

    08bcc5f
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/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.