Modify

Opened 16 years ago

Closed 16 years ago

#2249 closed defect (fixed)

New lexers not recognised by TracPygmentsPlugin

Reported by: TracPygmentsPlugin@… 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 Changed 16 years ago by Alec Thomas

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

comment:2 in reply to:  1 Changed 16 years ago by anonymous

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.py to make pygments aware of the new lexer

So what else is missing to get TracPygmentsPlugin to use the new lexer?

comment:3 Changed 16 years ago by anonymous

Resolution: fixed
Status: newclosed

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 mimetypes field:
    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

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Matt Good.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.