Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
difflib.HtmlDiff.make_file writes an HTML file with a CSS rule specifying Courier as the font to use. On systems which don't have it installed, browsers may fall back to the system default font, which likely won't be monospaced.
importdifflibimportwebbrowserhd=difflib.HtmlDiff()html=hd.make_file(["a","aab","c"+"f"*20,"eg","ry"], ["aab","f"*19,"ry"])withopen("diff.html","w")aswriter:print(html,file=writer)webbrowser.open("diff.html")
On my system (which does not have Courier), the default font is Signika, which is what Firefox used to render the text.
- Python 3.13.2 (main, Feb 5 2025, 08:05:21) [GCC 14.2.1 20250128]
- glibc 2.41+r9+ga900dbaf70f0-1
- Arch Linux (64-bit)
Ithink is is sufficient to do:
diff --git a/Lib/difflib.py b/Lib/difflib.pyindex bc09aa128aa..11d286a4aa8 100644--- a/Lib/difflib.py+++ b/Lib/difflib.py@@ -1633,7 +1633,7 @@ def _line_pair_iterator(): _styles = """ :root {color-scheme: light dark}- table.diff {font-family:Courier; border:medium;}+ table.diff {font-family:monospace; border:medium;} .diff_header {background-color:#e0e0e0} td.diff_header {text-align:right} .diff_next {background-color:#c0c0c0}
and will follow up with a pull request soon.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
