Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Description
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:
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.
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.
Additionally, the legend section has been visually enhanced—now more intuitive and aesthetically pleasing. And, of course, all browser warnings have been eliminated!
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