Opened 18 years ago
Closed 18 years ago
#2249 closed defect (fixed)
New lexers not recognised by TracPygmentsPlugin
| Reported by: | Owned by: | Matt Good | |
|---|---|---|---|
| Priority: | normal | Component: | TracPygmentsPlugin | 
| Severity: | normal | Keywords: | |
| Cc: | Trac Release: | 0.10 | 
Description
Hi I added a new lexer to the pygments package to get highlighting t a yet unsupported  language. It works fine when I call pygmentize in the console. However, the new lexer is not recognised by the TracPygmentsPlugin. It just wouldn't highlight the files in the Browser view. 
Do I still have to activate some kind of remapping (like it has to be done within pygments) to register any new lexers?
Attachments (0)
Change History (3)
comment:1 follow-up: 2 Changed 18 years ago by
comment:2 Changed 18 years ago by
Replying to athomas:
Have you read "http://trac-hacks.org/wiki/TracPygmentsPlugin#Options" ? Specifically
pygments_modes.
Sorry but I'm not that familiar with python programming and I couldn't make much out of that line of documentation. Also in the source code didn't help me either I'm afraid. Is there perhaps some easy solution? The things I have done to get pygmentize work with the new lexer are:
- go to the lexers directory
 - copy my newLexer.py into this directory (it's simply an adjusted copy of the already present lexers there
 - run: 
python _mapping.pyto make pygments aware of the new lexer 
So what else is missing to get TracPygmentsPlugin to use the new lexer?
comment:3 Changed 18 years ago by
| Resolution: | → fixed | 
|---|---|
| Status: | new → closed | 
Ok finally figured it out. It's just that a real example would have helped me earlier on. So just in case somebody else is as blind as me, here is my example:
- go to the lexers directory
 - copy (or symlink) the newLexer.py into this directory
 - in the new lexer definition also add a 
mimetypesfield:class NewLexer(RegexLexer): name = 'NewLexer' aliases = ['newlexer'] filenames = ['*.nlex'] mimetypes = ['text/x-newlexer']
 - run: python _mapping.py to make pygments aware of the new lexer
 - and now add in the 
trac.ini[mimeviewer] mime_map = text/x-newlexer:nlex pygments_modes = text/x-newlexer:newlexer:7
 - restart apache with 
apache2ctl graceful 



Have you read "http://trac-hacks.org/wiki/TracPygmentsPlugin#Options" ? Specifically
pygments_modes.