#5533 closed enhancement (fixed)
Add support for additional mime types using pygments get_all_lexers
Reported by: | loop | Owned by: | Christian Boos |
---|---|---|---|
Priority: | normal | Milestone: | 1.0 |
Component: | rendering | Version: | devel |
Severity: | major | Keywords: | actionscript pygments syntax coloring |
Cc: | Tim Hatch, lists@…, ryano@…, ethan.jucovy@… | Branch: | |
Release Notes: |
If Pygments support is enabled, all mimetypes supported by Pygments become automatically known to Trac |
||
API Changes: | |||
Internal Changes: |
Attachments (1)
Change History (24)
comment:1 by , 17 years ago
comment:3 by , 16 years ago
Component: | version control/browser → rendering |
---|---|
Milestone: | 0.11-retriage → 0.13 |
comment:4 by , 15 years ago
Milestone: | next-major-0.1X → 0.12 |
---|---|
Severity: | normal → major |
comment:6 by , 14 years ago
Milestone: | 0.12.1 → next-major-0.1X |
---|
comment:7 by , 14 years ago
Cc: | added |
---|---|
Summary: | actionscript mime type → Add support for additional mime types using pygments get_all_lexers |
Renaming the ticket because it's not actionscript-specific anymore.
comment:10 by , 12 years ago
Cc: | added |
---|
comment:11 by , 12 years ago
Cc: | added |
---|
by , 12 years ago
Attachment: | T5533_pygments_lexer_mimetypes.diff added |
---|
Adds pygments.lexers.get_all_lexers
info to MIME_MAP
follow-up: 13 comment:12 by , 12 years ago
Patch attachment:T5533_pygments_lexer_mimetypes.diff seems simple enough, am I missing something here?
comment:13 by , 12 years ago
Replying to psuter:
Patch attachment:T5533_pygments_lexer_mimetypes.diff seems simple enough, am I missing something here?
There's a possibility to miss an initial lookup with this approach…
A Mimeview.get_mimetype()
may happen first, for a repository file or an attachment, and the Pygments.get_quality_ratio(mimetype)
call happens then, after the mimetype has been (incorrectly) detected.
A refresh (forced refresh for an attachment) will do… but still, maybe we can think about an improved solution.
comment:14 by , 12 years ago
For example:
- [72aed033/cboos.git] 1.0dev: add
IHTMLPreviewRenderer.get_extra_mimetypes
method for augmenting the known mimetypes.
follow-up: 18 comment:17 by , 12 years ago
Sorry, I meant to check this. Yes, looks good.
The comment describing the new optional get_extra_mimetypes()
method on the IHTMLPreviewRenderer
interface could maybe be slightly improved. Currently it says Returning nothing is fine
, but return None
would not work.
More generally, how would a plugin know what the already known mime types are? Should it care? What about conflicts, priorities etc.? (Maybe out of scope for now.)
Also it doesn't really describe what the effect will be of adding additional mimetypes, and why this is related to HTML preview rendering.
Or maybe these details fit better in TracDev instead.
Targeting milestone 1.0 seems a bit risky for a plugin interface addition.
comment:18 by , 12 years ago
Replying to psuter:
Sorry, I meant to check this. Yes, looks good.
The comment describing the new optional
get_extra_mimetypes()
method on theIHTMLPreviewRenderer
interface could maybe be slightly improved. Currently it saysReturning nothing is fine
, butreturn None
would not work.
Ah yes, forgot the usual "... or []
" when iterating on providers.
More generally, how would a plugin know what the already known mime types are? Should it care? What about conflicts, priorities etc.? (Maybe out of scope for now.)
Well, if that's really a concern (i.e. a plugin wants only to add some types and not override them), then it can simply test via Mimeview(self.env).get_mimetype('file.keyword')
. If that's not enough and access to that component's _mime_map
is needed, we should indeed fix that with a better API (#3332 or something like that…).
Also it doesn't really describe what the effect will be of adding additional mimetypes, and why this is related to HTML preview rendering.
I've edited the docstring in this direction. It's true it has little to do with "HTML preview", except for the fact that IHTMLPreviewRenderer is what PygmentsRenderer implements and that IHTMLPreviewRenderer is already flagged as "to be merged in IContentConverter with an improved API", so this seems the best interim solution.
Or maybe these details fit better in TracDev instead.
Targeting milestone 1.0 seems a bit risky for a plugin interface addition.
Well, compared to the benefits this feature provides, I think this implementation is "good enough" and worth including in 1.0. I wanted to implement it since a very long time, and always failed because I didn't find a "clean" enough way to do it (short of bringing the whole #3332 topic on the table again). Your simple approach with add_mimetype
motivated me to find a middle ground.
comment:19 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Committed in r11228.
See log:cboos.git:ticket5533-get-extra-mimetypes-r11227 for the steps.
comment:20 by , 12 years ago
Release Notes: | modified (diff) |
---|
follow-up: 23 comment:21 by , 12 years ago
I was just looking through the changeset [11228#file1] and noticed that the name
variable is not used in get_extra_mimetypes
(pygments.py
), so wondering if it was intended to return name
as the second entry in the tuple rather than aliases
.
comment:22 by , 12 years ago
Note that after this change, the PatchRenderer
wouldn't handle the #!diff
WikiProcessor anymore (ticket:10840#comment:12). Fixed in r11319 for 1.0.1.
comment:23 by , 10 years ago
Replying to Ryan J Ollos <ryan.j.ollos@…>:
I was just looking through the changeset [11228#file1] and noticed that the
name
variable is not used inget_extra_mimetypes
(pygments.py
), so wondering if it was intended to returnname
as the second entry in the tuple rather thanaliases
.
Removed unused expression in [13185:13186].
Well, it would be nicer if we could do such things from the pygments renderer automatically, using the information provided by
pygments.lexers.get_all_lexers
. Related to #3332.