Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Wulian233
Copy link
Contributor

@Wulian233 Wulian233 commented May 23, 2025

Improved the styling of HTML diff pages generated by the difflib.HtmlDiff` class, and migrated the output to the HTML5 standard.
And all browser warnings have been eliminated.

details see: #134580

Request review @hugovk thanks!

Screenshot:

Before:

屏幕截图 2025-05-22 204245

After:
屏幕截图 2025-05-22 204257

Before:
屏幕截图 2025-05-22 204628

After:
屏幕截图 2025-05-22 210619


📚 Documentation preview 📚: https://cpython-previews--134581.org.readthedocs.build/

@hugovk
Copy link
Member

hugovk commented May 23, 2025

Thanks, I think this is an improvement.

Before

image

After

image

And

Here's a GitHub diff:

image

Similarly, I think we should keep the lines a bit tighter together.

Here's the PR with the vertical padding removed:

image

Shall we remove that padding?

And shall we centre the table on the page?

@Wulian233
Copy link
Contributor Author

Wulian233 commented May 23, 2025

Similarly, I think we should keep the lines a bit tighter together.
Here's the PR with the vertical padding removed:

It's a good improvement, and this is what it looks like now
屏幕截图 2025-05-23 211103

And shall we centre the table on the page?

I before thought about this, but the table width is determined based on the length of the content and the code specified, like

'<h2>tabsize=2</h2>',

             '<h2>tabsize=2</h2>',
             j.make_table(f2,t2),
             '<h2>tabsize=default</h2>',

屏幕截图 2025-05-23 211452

If we center the table, there will be a lot of space on both sides of the screen, and it may not be as easy to distinguish as if the table is narrow. So I didn't do that, and my opinion is also to keep the left alignment the way :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants