Mailing List Archive

When viewing a source ".c" file, Trac 1.5.4 shows it as an image
I'm using Trac 1.5.4.dev (trunk).

I just noticed that when viewing files from the repository, a .c file will
show as an image, but a .h file will show properly.

This is the kind of HTML that shows up within the web page:

<div id="preview" class="searchable">
<div class="image-file">
<img alt="(file path)" src="/trac/(project)/export/(file path)">
</div>
</div>

Interestingly, using the "c" processor will syntax highlight a code snippet
in the wiki.

Any ideas on how to convince Trac that those files are C source files?
Does a mime type need to be specified? It seems like that wasn't necessary
in the past.

Thanks.

- Dan

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/ad7d5974-153c-4d0a-aa1e-c4d24ca390f1n%40googlegroups.com.
Re: When viewing a source ".c" file, Trac 1.5.4 shows it as an image [ In reply to ]
FWIW, if I set the mime type to "text/x-csrc" it will highlight.

Also, although the .h file is shown, I think it's not highlighted. I
suppose if I set the mime type it would regain its mind.

I'll have to look deeper, I guess.

- Dan

On Tuesday, May 17, 2022 at 3:42:31 PM UTC-5 Dan wrote:

> I'm using Trac 1.5.4.dev (trunk).
>
> I just noticed that when viewing files from the repository, a .c file will
> show as an image, but a .h file will show properly.
>
> This is the kind of HTML that shows up within the web page:
>
> <div id="preview" class="searchable">
> <div class="image-file">
> <img alt="(file path)" src="/trac/(project)/export/(file path)">
> </div>
> </div>
>
> Interestingly, using the "c" processor will syntax highlight a code
> snippet in the wiki.
>
> Any ideas on how to convince Trac that those files are C source files?
> Does a mime type need to be specified? It seems like that wasn't necessary
> in the past.
>
> Thanks.
>
> - Dan
>

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/9b961a3c-fcd5-40fc-947d-38760d535e94n%40googlegroups.com.
Re: When viewing a source ".c" file, Trac 1.5.4 shows it as an image [ In reply to ]
It looks like this issue is due to pygments.lexers.get_all_lexers() having
multiple mime types associated with this extension.

('C', ('c',), ('*.c', '*.h', '*.idc', '*.x[bp]m'), ('text/x-chdr',
'text/x-csrc', 'image/x-xbitmap', 'image/x-xpixmap'))

So, in mimeview.py, Mimeview.mime_map(), there are multiple assignments to
self._mime_map[keyword] = mimetype

It will assign to the four items in the above list in turn. However,
self._mime_map will simply end up holding the last value.

I wonder if we should just use the first one we encounter, and ignore
subsequent attempts to override the value.

I am using Ubuntu 22. (pygments 2.11 or 2.12)

- Dan

On Tuesday, May 17, 2022 at 5:07:09 PM UTC-5 Dan wrote:

> FWIW, if I set the mime type to "text/x-csrc" it will highlight.
>
> Also, although the .h file is shown, I think it's not highlighted. I
> suppose if I set the mime type it would regain its mind.
>
> I'll have to look deeper, I guess.
>
> - Dan
>
> On Tuesday, May 17, 2022 at 3:42:31 PM UTC-5 Dan wrote:
>
>> I'm using Trac 1.5.4.dev (trunk).
>>
>> I just noticed that when viewing files from the repository, a .c file
>> will show as an image, but a .h file will show properly.
>>
>> This is the kind of HTML that shows up within the web page:
>>
>> <div id="preview" class="searchable">
>> <div class="image-file">
>> <img alt="(file path)" src="/trac/(project)/export/(file path)">
>> </div>
>> </div>
>>
>> Interestingly, using the "c" processor will syntax highlight a code
>> snippet in the wiki.
>>
>> Any ideas on how to convince Trac that those files are C source files?
>> Does a mime type need to be specified? It seems like that wasn't necessary
>> in the past.
>>
>> Thanks.
>>
>> - Dan
>>
>

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/342d6255-5f3d-403d-8f0c-5bf8da59927bn%40googlegroups.com.
Re: When viewing a source ".c" file, Trac 1.5.4 shows it as an image [ In reply to ]
Works for me, I guess. At least in this case.

Index: api.py
===================================================================
--- api.py (revision 17579)
+++ api.py (working copy)
@@ -930,7 +930,8 @@
for mimetype, kwds in renderer.get_extra_mimetypes()
or []:
self._mime_map[mimetype] = mimetype
for keyword in kwds:
- self._mime_map[keyword] = mimetype
+ if not keyword in self._mime_map:
+ self._mime_map[keyword] = mimetype
# augment/override mime_map from trac.ini
for mapping in self.config['mimeviewer'].getlist('mime_map'):
if ':' in mapping:


On Tuesday, May 17, 2022 at 7:19:55 PM UTC-5 Dan wrote:

> It looks like this issue is due to pygments.lexers.get_all_lexers() having
> multiple mime types associated with this extension.
>
> ('C', ('c',), ('*.c', '*.h', '*.idc', '*.x[bp]m'), ('text/x-chdr',
> 'text/x-csrc', 'image/x-xbitmap', 'image/x-xpixmap'))
>
> So, in mimeview.py, Mimeview.mime_map(), there are multiple assignments to
> self._mime_map[keyword] = mimetype
>
> It will assign to the four items in the above list in turn. However,
> self._mime_map will simply end up holding the last value.
>
> I wonder if we should just use the first one we encounter, and ignore
> subsequent attempts to override the value.
>
> I am using Ubuntu 22. (pygments 2.11 or 2.12)
>
> - Dan
>
> On Tuesday, May 17, 2022 at 5:07:09 PM UTC-5 Dan wrote:
>
>> FWIW, if I set the mime type to "text/x-csrc" it will highlight.
>>
>> Also, although the .h file is shown, I think it's not highlighted. I
>> suppose if I set the mime type it would regain its mind.
>>
>> I'll have to look deeper, I guess.
>>
>> - Dan
>>
>> On Tuesday, May 17, 2022 at 3:42:31 PM UTC-5 Dan wrote:
>>
>>> I'm using Trac 1.5.4.dev (trunk).
>>>
>>> I just noticed that when viewing files from the repository, a .c file
>>> will show as an image, but a .h file will show properly.
>>>
>>> This is the kind of HTML that shows up within the web page:
>>>
>>> <div id="preview" class="searchable">
>>> <div class="image-file">
>>> <img alt="(file path)" src="/trac/(project)/export/(file path)">
>>> </div>
>>> </div>
>>>
>>> Interestingly, using the "c" processor will syntax highlight a code
>>> snippet in the wiki.
>>>
>>> Any ideas on how to convince Trac that those files are C source files?
>>> Does a mime type need to be specified? It seems like that wasn't necessary
>>> in the past.
>>>
>>> Thanks.
>>>
>>> - Dan
>>>
>>

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/c3fdbd1d-2e57-418a-a4fa-22a01c38dcfan%40googlegroups.com.
Re: Re: When viewing a source ".c" file, Trac 1.5.4 shows it as an image [ In reply to ]
On Wed, May 18, 2022 at 9:20 AM Dan <dan.mahn@digidescorp.com> wrote:
>
> It looks like this issue is due to pygments.lexers.get_all_lexers() having multiple mime types associated with this extension.
>
> ('C', ('c',), ('*.c', '*.h', '*.idc', '*.x[bp]m'), ('text/x-chdr', 'text/x-csrc', 'image/x-xbitmap', 'image/x-xpixmap'))
>
> So, in mimeview.py, Mimeview.mime_map(), there are multiple assignments to self._mime_map[keyword] = mimetype
>
> It will assign to the four items in the above list in turn. However, self._mime_map will simply end up holding the last value.
>
> I wonder if we should just use the first one we encounter, and ignore subsequent attempts to override the value.
>
> I am using Ubuntu 22. (pygments 2.11 or 2.12)
>
> - Dan

Good catch! I just reproduced the issue with Pygments 2.12.0 instead of 2.10.0.
Could you please create new ticket on https://trac.edgewall.org/newticket?

--
Jun Omae <jun66j5@gmail.com> (?? ?)

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/CAEVLMajnKEQ6DEGDMs5aBaAo3nog2eB0QcxF4-GUjhmwHkJSGA%40mail.gmail.com.
Re: When viewing a source ".c" file, Trac 1.5.4 shows it as an image [ In reply to ]
Or ... Adding "text/x-csrc:c" to the "mime_map" configuration list also
works, but it seems like a software-development-oriented system shouldn't
need to special-case common software source files.

- Dan

On Tuesday, May 17, 2022 at 7:26:22 PM UTC-5 Dan wrote:

> Works for me, I guess. At least in this case.
>
> Index: api.py
> ===================================================================
> --- api.py (revision 17579)
> +++ api.py (working copy)
> @@ -930,7 +930,8 @@
> for mimetype, kwds in renderer.get_extra_mimetypes()
> or []:
> self._mime_map[mimetype] = mimetype
> for keyword in kwds:
> - self._mime_map[keyword] = mimetype
> + if not keyword in self._mime_map:
> + self._mime_map[keyword] = mimetype
> # augment/override mime_map from trac.ini
> for mapping in self.config['mimeviewer'].getlist('mime_map'):
> if ':' in mapping:
>
>
> On Tuesday, May 17, 2022 at 7:19:55 PM UTC-5 Dan wrote:
>
>> It looks like this issue is due to pygments.lexers.get_all_lexers()
>> having multiple mime types associated with this extension.
>>
>> ('C', ('c',), ('*.c', '*.h', '*.idc', '*.x[bp]m'), ('text/x-chdr',
>> 'text/x-csrc', 'image/x-xbitmap', 'image/x-xpixmap'))
>>
>> So, in mimeview.py, Mimeview.mime_map(), there are multiple assignments
>> to self._mime_map[keyword] = mimetype
>>
>> It will assign to the four items in the above list in turn. However,
>> self._mime_map will simply end up holding the last value.
>>
>> I wonder if we should just use the first one we encounter, and ignore
>> subsequent attempts to override the value.
>>
>> I am using Ubuntu 22. (pygments 2.11 or 2.12)
>>
>> - Dan
>>
>> On Tuesday, May 17, 2022 at 5:07:09 PM UTC-5 Dan wrote:
>>
>>> FWIW, if I set the mime type to "text/x-csrc" it will highlight.
>>>
>>> Also, although the .h file is shown, I think it's not highlighted. I
>>> suppose if I set the mime type it would regain its mind.
>>>
>>> I'll have to look deeper, I guess.
>>>
>>> - Dan
>>>
>>> On Tuesday, May 17, 2022 at 3:42:31 PM UTC-5 Dan wrote:
>>>
>>>> I'm using Trac 1.5.4.dev (trunk).
>>>>
>>>> I just noticed that when viewing files from the repository, a .c file
>>>> will show as an image, but a .h file will show properly.
>>>>
>>>> This is the kind of HTML that shows up within the web page:
>>>>
>>>> <div id="preview" class="searchable">
>>>> <div class="image-file">
>>>> <img alt="(file path)" src="/trac/(project)/export/(file path)">
>>>> </div>
>>>> </div>
>>>>
>>>> Interestingly, using the "c" processor will syntax highlight a code
>>>> snippet in the wiki.
>>>>
>>>> Any ideas on how to convince Trac that those files are C source files?
>>>> Does a mime type need to be specified? It seems like that wasn't necessary
>>>> in the past.
>>>>
>>>> Thanks.
>>>>
>>>> - Dan
>>>>
>>>

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/002d2b53-ebe9-42a9-8224-7eb07c5c32f9n%40googlegroups.com.
Re: Re: When viewing a source ".c" file, Trac 1.5.4 shows it as an image [ In reply to ]
On Wed, May 18, 2022 at 10:35 AM Jun Omae <jun66j5@gmail.com> wrote:
>
> On Wed, May 18, 2022 at 9:20 AM Dan <dan.mahn@digidescorp.com> wrote:
> >
> > It looks like this issue is due to pygments.lexers.get_all_lexers() having multiple mime types associated with this extension.
> >
> > ('C', ('c',), ('*.c', '*.h', '*.idc', '*.x[bp]m'), ('text/x-chdr', 'text/x-csrc', 'image/x-xbitmap', 'image/x-xpixmap'))
> >
> > So, in mimeview.py, Mimeview.mime_map(), there are multiple assignments to self._mime_map[keyword] = mimetype
> >
> > It will assign to the four items in the above list in turn. However, self._mime_map will simply end up holding the last value.
> >
> > I wonder if we should just use the first one we encounter, and ignore subsequent attempts to override the value.
> >
> > I am using Ubuntu 22. (pygments 2.11 or 2.12)
> >
> > - Dan
>
> Good catch! I just reproduced the issue with Pygments 2.12.0 instead of 2.10.0.
> Could you please create new ticket on https://trac.edgewall.org/newticket?

I just filed at https://trac.edgewall.org/ticket/13483.

--
Jun Omae <jun66j5@gmail.com> (?? ?)

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/CAEVLMahattA-MAiFeM1fjJwkvGcD%2Bp-q0bdwayXc_v%2BgULH90g%40mail.gmail.com.
Re: Re: When viewing a source ".c" file, Trac 1.5.4 shows it as an image [ In reply to ]
Thanks!

Interestingly I didn't see your first reply, and I'm still not sure where
that one went. But thanks again for going ahead with the ticket.

- Dan

On Thursday, May 19, 2022 at 8:22:56 AM UTC-5 Jun Omae wrote:

> On Wed, May 18, 2022 at 10:35 AM Jun Omae <jun...@gmail.com> wrote:
> >
> > On Wed, May 18, 2022 at 9:20 AM Dan <dan....@digidescorp.com> wrote:
> > >
> > > It looks like this issue is due to pygments.lexers.get_all_lexers()
> having multiple mime types associated with this extension.
> > >
> > > ('C', ('c',), ('*.c', '*.h', '*.idc', '*.x[bp]m'), ('text/x-chdr',
> 'text/x-csrc', 'image/x-xbitmap', 'image/x-xpixmap'))
> > >
> > > So, in mimeview.py, Mimeview.mime_map(), there are multiple
> assignments to self._mime_map[keyword] = mimetype
> > >
> > > It will assign to the four items in the above list in turn. However,
> self._mime_map will simply end up holding the last value.
> > >
> > > I wonder if we should just use the first one we encounter, and ignore
> subsequent attempts to override the value.
> > >
> > > I am using Ubuntu 22. (pygments 2.11 or 2.12)
> > >
> > > - Dan
> >
> > Good catch! I just reproduced the issue with Pygments 2.12.0 instead of
> 2.10.0.
> > Could you please create new ticket on
> https://trac.edgewall.org/newticket?
>
> I just filed at https://trac.edgewall.org/ticket/13483.
>
> --
> Jun Omae <jun...@gmail.com> (?? ?)
>

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/28312295-8ac4-47eb-a3c5-94d24ba1580cn%40googlegroups.com.