Edgewall Software

Changes between Initial Version and Version 1 of 1.1/TracSyntaxColoring


Ignore:
Timestamp:
Oct 27, 2014, 6:14:38 AM (10 years ago)
Author:
Ryan J Ollos
Comment:

Copied from TracSyntaxColoring@57.

Legend:

Unmodified
Added
Removed
Modified
  • 1.1/TracSyntaxColoring

    v1 v1  
     1** Note: this page documents the 1.0 version of Trac, see [[0.12/TracSyntaxColoring]] if you need the previous version **
     2= Syntax Coloring of Source Code =
     3[[TranslatedPages]]
     4Trac supports language-specific syntax highlighting of source code within wiki formatted text in [WikiProcessors#CodeHighlightingSupport wiki processors] blocks and in the [TracBrowser repository browser].
     5
     6To do this, Trac uses external libraries with support for a great number of programming languages.
     7
     8Currently Trac supports syntax coloring using one or more of the following packages:
     9
     10 * [http://pygments.pocoo.org/ Pygments], by far the preferred system, as it covers a wide range of programming languages and other structured texts and is actively supported
     11 * [http://www.codento.com/people/mtr/genscript/ GNU Enscript], commonly available on Unix but somewhat unsupported on Windows //(use is deprecated)//
     12 * [http://silvercity.sourceforge.net/ SilverCity], legacy system, some versions can be problematic //(use is deprecated)//
     13
     14
     15To activate syntax coloring, simply install either one (or more) of these packages (see [#ExtraSoftware] section below).
     16If none of these packages is available, Trac will display the data as plain text.
     17
     18
     19=== About Pygments ===
     20
     21Since Trac 0.11 [http://pygments.org/ pygments] is the new default highlighter. It's a highlighting library implemented in pure python, very fast, easy to extend and [http://pygments.org/docs/ well documented].
     22
     23The Pygments default style can specified in the [TracIni#mimeviewer-section mime-viewer] section of trac.ini. The default style can be overridden by setting a Style preference on the [/prefs/pygments preferences page].
     24
     25It'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 [http://pygments.org/docs/lexers/ supported lexers] on the pygments webpage.
     26
     27
     28== Syntax Coloring Support ==
     29
     30=== Known MIME Types
     31
     32[[KnownMimeTypes]]
     33
     34Note that the rich content may be directly //rendered// instead of syntax highlighted. This usually depends on which auxiliary packages are installed and on which components are activated in your setup. For example a `text/x-rst` document will be rendered via `docutils` if it is installed and the `trac.mimeview.rst.ReStructuredTextRenderer` is not disabled, and will be syntax highlighted otherwise.
     35
     36In a similar way, a document with the mimetype `text/x-trac-wiki` is rendered using the Trac wiki formatter, unless the `trac.mimeview.api.WikiTextRenderer` component is disabled.
     37
     38HTML documents are directly rendered only if the `render_unsafe_html` settings are enabled in the TracIni (those settings are present in multiple sections, as there are different security concerns depending where the document comes from). If you want to ensure that an HTML document gets syntax highlighted and not rendered, use the `text/xml` mimetype.
     39
     40If a mimetype property such as 'svn:mime-type' is set to 'text/plain', there is no coloring even if file is known type like 'java'.
     41
     42=== List of Languages Supported, by Highlighter #language-supported
     43
     44This list is only indicative.
     45
     46||                 ||= !SilverCity   =||= Enscript      =||= Pygments =||
     47|| Ada             ||                 ||  ✓              ||     ||
     48|| Asm             ||                 ||  ✓              ||     ||
     49|| Apache Conf     ||                 ||                 ||  ✓  ||
     50|| ASP             ||  ✓              ||  ✓              ||     ||
     51|| C               ||  ✓              ||  ✓              ||  ✓  ||
     52|| C#              ||                 ||  ✓ ^[#a1 (1)]^  ||  ✓  ||
     53|| C++             ||  ✓              ||  ✓              ||  ✓  ||
     54|| CMake           ||  ?              ||  ?              ||  ✓  ||
     55|| Java            ||  ✓ ^[#a2 (2)]^  ||  ✓              ||  ✓  ||
     56|| Awk             ||                 ||  ✓              ||     ||
     57|| Boo             ||                 ||                 ||  ✓  ||
     58|| CSS             ||  ✓              ||                 ||  ✓  ||
     59|| Python Doctests ||                 ||                 ||  ✓  ||
     60|| Diff            ||                 ||  ✓              ||  ✓  ||
     61|| Eiffel          ||                 ||  ✓              ||     ||
     62|| Elisp           ||                 ||  ✓              ||     ||
     63|| Fortran         ||                 ||  ✓ ^[#a1 (1)]^  ||  ✓  ||
     64|| Haskell         ||                 ||  ✓              ||  ✓  ||
     65|| Genshi          ||                 ||                 ||  ✓  ||
     66|| HTML            ||  ✓              ||  ✓              ||  ✓  ||
     67|| IDL             ||                 ||  ✓              ||     ||
     68|| INI             ||                 ||                 ||  ✓  ||
     69|| Javascript      ||  ✓              ||  ✓              ||  ✓  ||
     70|| Lua             ||                 ||                 ||  ✓  ||
     71|| m4              ||                 ||  ✓              ||     ||
     72|| Makefile        ||                 ||  ✓              ||  ✓  ||
     73|| Mako            ||                 ||                 ||  ✓  ||
     74|| Matlab ^[#a3 (3)]^  ||             ||  ✓              ||  ✓  ||
     75|| Mygthy          ||                 ||                 ||  ✓  ||
     76|| Objective-C     ||                 ||  ✓              ||  ✓  ||
     77|| OCaml           ||                 ||                 ||  ✓  ||
     78|| Pascal          ||                 ||  ✓              ||  ✓  ||
     79|| Perl            ||  ✓              ||  ✓              ||  ✓  ||
     80|| PHP             ||  ✓              ||                 ||  ✓  ||
     81|| PSP             ||  ✓              ||                 ||     ||
     82|| Pyrex           ||                 ||  ✓              ||     ||
     83|| Python          ||  ✓              ||  ✓              ||  ✓  ||
     84|| Ruby            ||  ✓              ||  ✓ ^[#a1 (1)]^  ||  ✓  ||
     85|| Scheme          ||                 ||  ✓              ||  ✓  ||
     86|| Shell           ||                 ||  ✓              ||  ✓  ||
     87|| Smarty          ||                 ||                 ||  ✓  ||
     88|| SQL             ||  ✓              ||  ✓              ||  ✓  ||
     89|| Troff           ||                 ||  ✓              ||  ✓  ||
     90|| TCL             ||                 ||  ✓              ||     ||
     91|| Tex             ||                 ||  ✓              ||  ✓  ||
     92|| Verilog         ||  ✓ ^[#a2 (2)]^  ||  ✓              ||     ||
     93|| VHDL            ||                 ||  ✓              ||     ||
     94|| Visual Basic    ||                 ||  ✓              ||  ✓  ||
     95|| VRML            ||                 ||  ✓              ||     ||
     96|| XML             ||  ✓              ||                 ||  ✓  ||
     97
     98
     99
     100''[=#a1 (1)] Not included in the Enscript distribution.  Additional highlighting rules can be obtained for
     101[http://neugierig.org/software/ruby/ Ruby],
     102[http://wiki.hasno.info/index.php/Csharp.st C#],
     103[http://wiki.hasno.info/index.php/F90.st Fortran 90x/2003]
     104
     105''[=#a2 (2)] since Silvercity 0.9.7 released on 2006-11-23
     106
     107''[=#a3 (3)] By default `.m` files are considered Objective-C files. In order to treat `.m` files as MATLAB files, add "text/matlab:m" to the "mime_map" setting in the [wiki:TracIni#mimeviewer-section "[mimeviewer] section of trac.ini"].
     108
     109== Extra Software ==
     110 * GNU Enscript — http://directory.fsf.org/GNU/enscript.html
     111 * GNU Enscript for Windows — http://gnuwin32.sourceforge.net/packages/enscript.htm
     112 * !SilverCity — http://silvercity.sf.net/
     113 * **Pygments — http://pygments.org/**
     114
     115----
     116See also: WikiProcessors, WikiFormatting, TracWiki, TracBrowser