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

difflib-generated HTML file does not use monospaced font #131204

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@tfpf

Description

@tfpf

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.

Image

  • 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

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp