#13483 closed defect (fixed)
File viewer renders *.c file as an image with Pygments 2.11 - 2.12
Reported by: | Jun Omae | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Milestone: | 1.5.4 |
Component: | rendering | Version: | 1.5.3 |
Severity: | normal | Keywords: | pygments |
Cc: | Branch: | ||
Release Notes: |
Perfer |
||
API Changes: | |||
Internal Changes: |
Description
Reported at gmessage:trac-users:iOcdoLFjKZg/m/IsjjrUZgEgAJ.
Attachments (0)
Change History (4)
comment:1 by , 3 years ago
comment:2 by , 3 years ago
PygmentsRenderer.get_extra_mimetypes()
with Pygments 2.11+ returns multiple mimetypes for c
.
>>> from trac.test import EnvironmentStub >>> from trac.mimeview.api import Mimeview >>> from trac.mimeview.pygments import PygmentsRenderer >>> env = EnvironmentStub() >>> mimeview = Mimeview(env) >>> mimeview.mime_map['c'] 'image/x-xpixmap' >>> mimeview.get_mimetype('filename.c') 'image/x-xpixmap; charset=utf-8' >>> renderer = PygmentsRenderer(env) >>> list(renderer.get_system_info()) [('Pygments', '2.12.0')] >>> for mimetype, kwds in renderer.get_extra_mimetypes(): ... if 'c' in kwds: print(mimetype, kwds) ... text/x-chdr ('c',) text/x-csrc ('c',) image/x-xbitmap ('c',) image/x-xpixmap ('c',)
When Pygments 2.10.0 is used:
>>> mimeview = Mimeview(env) >>> renderer = PygmentsRenderer(env) >>> list(renderer.get_system_info()) [('Pygments', '2.10.0')] >>> mimeview.mime_map['c'] 'text/x-csrc' >>> mimeview.get_mimetype('filename.c') 'text/x-csrc; charset=utf-8' >>> for mimetype, kwds in renderer.get_extra_mimetypes(): ... if 'c' in kwds: print(mimetype, kwds) ... text/x-chdr ('c',) text/x-csrc ('c',)
Work around is to avoid one alias having multiple mimetypes like this:
-
trac/mimeview/pygments.py
diff --git a/trac/mimeview/pygments.py b/trac/mimeview/pygments.py index 3be2d9c7c..cd963fab5 100644
a b class PygmentsRenderer(Component): 109 109 for _, aliases, _, mimetypes in get_all_lexers(): 110 110 for mimetype in mimetypes: 111 111 yield mimetype, aliases 112 aliases = () # avoid one alias having multiple mimetypes 112 113 113 114 def get_quality_ratio(self, mimetype): 114 115 # Extend default MIME type to mode mappings with configured ones
After the changes:
>>> from trac.test import EnvironmentStub >>> from trac.mimeview.api import Mimeview >>> from trac.mimeview.pygments import PygmentsRenderer >>> env = EnvironmentStub() >>> mimeview = Mimeview(env) >>> mimeview.mime_map['c'] 'text/x-chdr' >>> mimeview.get_mimetype('filename.c') 'text/x-chdr; charset=utf-8' >>> for mimetype, kwds in renderer.get_extra_mimetypes(): ... if 'c' in kwds: print(mimetype, kwds) ... text/x-chdr ('c',)
comment:3 by , 2 years ago
Keywords: | pygments added |
---|---|
Owner: | set to |
Status: | new → assigned |
Proposed changes in [a5d3519b1/jomae.git] (jomae.git@t13483). After the changes, text/*
type will be preferred in order to prevent rendering as an image for *.c
filename.
comment:4 by , 2 years ago
Release Notes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
Pushed in [17623].
Root cause is https://github.com/pygments/pygments/commit/1f44b277737f88a4402032584660d84a671fb79d