Opened 9 years ago

Closed 9 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


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 9 years ago by Alec Thomas

Have you read "" ? Specifically pygments_modes.

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

Replying to athomas:

Have you read "" ? 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 into this directory (it's simply an adjusted copy of the already present lexers there
  • run: python to make pygments aware of the new lexer

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

comment:3 Changed 9 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 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 to make pygments aware of the new lexer
  • and now add in the trac.ini
    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
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.