Bug 514773 - syntax highlighting not working
syntax highlighting not working
Product: Fedora
Classification: Fedora
Component: viewvc (Show other bugs)
All Linux
low Severity medium
: ---
: ---
Assigned To: Bojan Smojver
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2009-07-30 13:38 EDT by Zing
Modified: 2009-08-12 16:55 EDT (History)
2 users (show)

See Also:
Fixed In Version: 1.1.2-2.fc11
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2009-08-12 16:55:38 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

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

  None (edit)
Description Zing 2009-07-30 13:38:48 EDT
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 13:42:20 EDT
Created attachment 355711 [details]
my viewvc config - slightly edited
Comment 2 Bojan Smojver 2009-07-30 19:55:19 EDT
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-30 20:03:42 EDT
Which is actually surprising, because C lexer is included. Hmm, maybe something to do with mime types...
Comment 4 Zing 2009-07-30 20:30:53 EDT
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-30 22:16:18 EDT
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-30 22:25:54 EDT
> 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-30 22:59:52 EDT
> 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-30 23:07:47 EDT
Ah, yeah. You are right, of course. Sorry :-(
Comment 9 Bojan Smojver 2009-08-06 01:50:29 EDT
Question: if you put mimetypes.conf from bug #514909 in /etc/viewvc, is this patch still required?
Comment 10 Zing 2009-08-06 21:05:26 EDT
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-06 21:09:47 EDT
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-06 21:11:26 EDT
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-06 21:23:02 EDT

Sorry, all this is taking so long. Don't have much time these days...
Comment 14 Zing 2009-08-06 21:37:44 EDT
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-10 23:34:54 EDT
viewvc-1.1.1-2.fc11 has been submitted as an update for Fedora 11.
Comment 16 Fedora Update System 2009-08-11 18:34:54 EDT
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 19:11:30 EDT
viewvc-1.1.2-1.fc11 has been submitted as an update for Fedora 11.
Comment 18 Fedora Update System 2009-08-12 16:55:24 EDT
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.