Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Modernizingdifflib.HtmlDiff for HTML Output #134580

Open
Labels
stdlibPython modules in the Lib dirtype-featureA feature request or enhancement
@Wulian233

Description

@Wulian233

Feature or enhancement

Proposal:

Previously, I added dark mode support to the HTML export feature ofdifflib, 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:

<metahttp-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 remainsbackward-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 modernizedifflib.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp