Bug 514773 - syntax highlighting not working
Summary: syntax highlighting not working
Alias: None
Product: Fedora
Classification: Fedora
Component: viewvc
Version: 11
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Bojan Smojver
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2009-07-30 17:38 UTC by Zing
Modified: 2009-08-12 20:55 UTC (History)
2 users (show)

Fixed In Version: 1.1.2-2.fc11
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2009-08-12 20:55:38 UTC
Type: ---

Attachments (Terms of Use)
my viewvc config - slightly edited (31.43 KB, text/plain)
2009-07-30 17:42 UTC, Zing
no flags Details

Description Zing 2009-07-30 17:38:48 UTC
Description of problem:
I have "enable_syntax_coloration = 1", but I'm not seeing any color highlighting.  There isn't any exception raised, I get the view of the code, but it's just not highlighted.

I've tried running pygmentize on the command line, dumping out an html file and that works fine.

I've been trying to pinpoint what's happening, but haven't had much luck.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. "enable_syntax_coloration = 1" in viewvc.conf
2. code isn't colored/highlighted.
Actual results:
no color highlighting.

Expected results:
color highlighting.

Comment 1 Zing 2009-07-30 17:42:20 UTC
Created attachment 355711 [details]
my viewvc config - slightly edited

Comment 2 Bojan Smojver 2009-07-30 23:55:19 UTC
What kind of file are you trying to see coloured? There is only a limited number of lexers shipped with python-pygments in Fedora. For instance, I can see SQL and XML coloured, but not C.

Comment 3 Bojan Smojver 2009-07-31 00:03:42 UTC
Which is actually surprising, because C lexer is included. Hmm, maybe something to do with mime types...

Comment 4 Zing 2009-07-31 00:30:53 UTC
Ahh, you're right.  I had never tried anything other than C code.  I do see color for some CSS files I have checked in, which are shown in the interface as mime type text/css.  The C code is shown as mime type text/plain.

Comment 5 Zing 2009-07-31 02:16:18 UTC
Are you sure there is a "limited" number of lexers in fedora?  pygmentize -L dumps quite a lot of lexers to me?

Anyway, thanks for the mime_type hint... I've hacked this in temporarily for now to get color (this logic seems more sane to me, but i don't know the code at all):

--- viewvc.py.orig	2009-07-30 22:11:36.000000000 -0400
+++ viewvc.py	2009-07-30 22:10:01.000000000 -0400
@@ -1363,10 +1363,10 @@
                                 get_lexer_for_mimetype, \
-      lexer = get_lexer_for_mimetype(mime_type)
+      lexer = get_lexer_for_filename(filename)
     except ClassNotFound:
-        lexer = get_lexer_for_filename(filename)
+        lexer = get_lexer_for_mimetype(mime_type)
       except ClassNotFound:
         use_pygments = 0
   except ImportError:

Comment 6 Bojan Smojver 2009-07-31 02:25:54 UTC
> Are you sure there is a "limited" number of lexers in fedora?  pygmentize -L
dumps quite a lot of lexers to me?

No, I thought something was missed, because I didn't see a C lexer there at first. It is in the compiled lexers collection. Red herring, sorry.

Maybe we can do that path to try the lexer for mime_type first and if that's not found try for filename?

Comment 7 Zing 2009-07-31 02:59:52 UTC
> Maybe we can do that path to try the lexer for mime_type first and if that's
> not found try for filename?  

I think you may have misread the diff... that is exactly what the code does now.  

That's the problem though (at least I think), viewvc first decides, prior to these calls, that the mimetype for *.c files is text/plain, so calling get_lexer_for_mimetype() first chooses the pygments "text" lexer and goes on its merry way... which I guess is no color when it comes to highlighting, at least for C files.

So I just swapped the calls, so that pygments figures it out by by filename itself.  It does seems better to me to let pygments do the figuring out.

Now, I don't really know going forward what the right thing to do would be.  
Ultimately anything that gets me color that "just works" out of the box would be the goal.

Comment 8 Bojan Smojver 2009-07-31 03:07:47 UTC
Ah, yeah. You are right, of course. Sorry :-(

Comment 9 Bojan Smojver 2009-08-06 05:50:29 UTC
Question: if you put mimetypes.conf from bug #514909 in /etc/viewvc, is this patch still required?

Comment 10 Zing 2009-08-07 01:05:26 UTC
It depends. :)

If you put the default mimetypes.conf in /etc/viewvc, you still need the patch, because the default conf file is empty and viewvc still "misrecognizes" .c files as the wrong mimetype... no highlighting.

But if add the line:

text/x-csrc     c

viewvc will then start highlighting .c files... without the patch.

Personally, though, I don't particularly like that solution.  While it would avoid patching the source, one would then presumably go through all the lexers and extensions supported by pygments, test to see if viewvc detects the mimetype "correctly", and if not, add the "correct" mimetype/extension to mimetypes.conf.  That doesn't strike me as what a site-specific mimetypes.conf was made for.  Plus, as pygments supports more lexers over time, you'd have to continually update this file to match.

Comment 11 Zing 2009-08-07 01:09:47 UTC
I'd just like reiterate, that patch was just a quick hack to make highlighting work for me here right now... it might be worth seeing what upstream thinks?

Comment 12 Bojan Smojver 2009-08-07 01:11:26 UTC
Yeah, that sucks. They should just ship the file filled with whatever lexers support. Anyway, thanks for letting me know.

Comment 13 Bojan Smojver 2009-08-07 01:23:02 UTC

Sorry, all this is taking so long. Don't have much time these days...

Comment 14 Zing 2009-08-07 01:37:44 UTC
No worries.  I'm in no rush.  all the necessary info is here, so if people need to get it working they can help themselves.  :)

Comment 15 Fedora Update System 2009-08-11 03:34:54 UTC
viewvc-1.1.1-2.fc11 has been submitted as an update for Fedora 11.

Comment 16 Fedora Update System 2009-08-11 22:34:54 UTC
viewvc-1.1.1-2.fc11 has been pushed to the Fedora 11 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update viewvc'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F11/FEDORA-2009-8481

Comment 17 Fedora Update System 2009-08-11 23:11:30 UTC
viewvc-1.1.2-1.fc11 has been submitted as an update for Fedora 11.

Comment 18 Fedora Update System 2009-08-12 20:55:24 UTC
viewvc-1.1.2-2.fc11 has been pushed to the Fedora 11 stable repository.  If problems still persist, please make note of it in this bug report.

Note You need to log in before you can comment on or make changes to this bug.