Computational Neuroscience at UMB, Ås
Syntax Coloring of Source Code
To do this, Trac uses external libraries with support for a great number of programming languages.
Currently Trac supports syntax coloring using one or more of the following packages:
To activate syntax coloring, simply install either one (or more) of these packages. No additional configuration is required, however to modify the colors, have a look at trac/htdocs/css/code.css.
If you don't know why trac isnt detecting an installed library, try turning on Trac logging. It actually appears that Trac is broken with SilverCity? 0.9.6. Either use the current 0.9.7 or the older 0.9.5 http://trac.edgewall.org/wiki/TracFaq#why-is-my-css-code-not-being-highlighted-even-though-i-have-silvercity-installed
When in use, Trac will automatically prioritize SilverCity highlighting over Enscript if possible, (see note below).
If neither package is available, Trac will display the data as plain text.
Note: Enscript supports a greater number of languages, however SilverCity is generally faster since it is a library and isn't executed in an external process.
SilverCity uses the lexer from Scintilla. Scintilla supports more languages than SilverCity implements. If you want to add a language to SilverCity supported by Scintilla, it's not very difficult. See SilverCityAddLanguage for some information how.
Starting with trac 0.11 pygments will be the new default highlighter. It's a highlighting library implemented in pure python, very fast, easy to extend and well documented. While it does not support as many languages as Enscript or Scintilla the overall output quality is much better.
To use pygments in trac 0.11 you just have to install pygments 0.6 or higher (pygments_default_style = colorful under [mimeviewer] options has to be added).If you want to use it in trac 0.10 too you have to install the TracPygmentsPlugin from trac hacks. If you encounter any bugs, please file tickets regarding Pygments in the pygments trac.
It's very likely that the list below is outdated because the list of supported pygments lexers is growing weekly. Just have a look at the page of supported lexers on the pygments webpage.
Syntax Coloring Support
|Apache Conf (htaccess))||X|
|* Ruby||X||X (1)||X|
(1) Ruby highlighting is not included in the Enscript distribution. Highlighting rules for Ruby can be obtained from: http://neugierig.org/software/ruby/
(2) C# highlighting is not included in the Enscript distribution. Highlighting rules for C# can be obtained from: http://wiki.hasno.info/index.php/Csharp.st
(3) Fortran: as packaged, Enscript only supports the fixed source form. Highlighting rules for Fortran 90x/2003 can be obtained from: http://wiki.hasno.info/index.php/F90.st
(4) since Silvercity 0.9.7 released on 2006-11-23
(5) By default .m files are considered Objective-C files. In order to treat .m files as MATLAB files, add "text/x-matlab:m" to the "mime_map" setting in the [mimeviewer] section of trac.ini.
- GNU Enscript -- http://directory.fsf.org/GNU/enscript.html
- GNU Enscript for Windows -- http://gnuwin32.sourceforge.net/packages/enscript.htm
- SilverCity -- http://silvercity.sf.net/
- Pygments -- http://pygments.org/