Version 3 (modified by trac, 8 years ago) (diff) |
---|
Syntax Coloring of Source Code
Trac supports language-specific syntax highlighting of source code within wiki formatted text in wiki processors blocks and in the repository browser.
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:
- Pygments, by far the preferred system, as it covers a wide range of programming languages and other structured texts and is actively supported
- GNU Enscript, commonly available on Unix but somewhat unsupported on Windows
- SilverCity, legacy system, some versions can be problematic
To activate syntax coloring, simply install either one (or more) of these packages (see #ExtraSoftware section below). If none of these packages is available, Trac will display the data as plain text.
About Pygments
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.
The Pygments default style can specified in the mime-viewer section of trac.ini. The default style can be overridden by setting a Style preference on the preferences page.
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
Known MIME Types
MIME Types | WikiProcessors |
---|---|
application/atom+xml | xml |
application/json | json |
application/msword | doc dot |
application/pdf | pdf |
application/postscript | postscript ps |
application/rss+xml | rss |
application/rtf | rtf |
application/x-awk | awk gawk mawk nawk |
application/x-befunge | befunge |
application/x-brainfuck | bf brainfuck |
application/x-clojure | clj clojure |
application/x-coldfusion | cfm |
application/x-csh | csh tcsh |
application/x-cython | cython pyx |
application/x-dos-batch | bat |
application/x-ecl | ecl |
application/x-evoque | evoque |
application/x-fantom | fan |
application/x-gooddata-maql | maql |
application/x-httpd-lasso[89] | html+lasso |
application/x-httpd-php5 | html+php |
application/x-hybris | hy hybris |
application/x-jinja | django jinja |
application/x-jsp | jsp |
application/x-julia | jl julia |
application/x-kid | genshi kid xml+genshi xml+kid |
application/x-lua | lua |
application/x-mako | mako |
application/x-mason | mason |
application/x-moonscript | moon moonscript |
application/x-myghty | myghty |
application/x-newlisp | newlisp |
application/x-openedge | abl openedge progress |
application/x-perl | perl pl |
application/x-pygments-tokens | raw |
application/x-pypylog | pypy pypylog |
application/x-python | py python sage |
application/x-python3 | py3 python3 |
application/x-qml | Qt Meta Language Qt modeling Language qml |
application/x-racket | racket rkt |
application/x-ruby | duby rb ruby |
application/x-ruby-templating | erb |
application/x-scheme | scheme scm |
application/x-sh-session | shell-session |
application/x-shell-session | console |
application/x-shellscript | bash ksh sh |
application/x-smarty | smarty |
application/x-spitfire | cheetah spitfire |
application/x-ssp | ssp |
application/x-standardml | sml |
application/x-tcl | tcl |
application/x-troff | roff troff |
application/x-urbiscript | urbiscript |
application/x-yaml | yml |
application/xhtml+xml | html |
application/xml+evoque | xml+evoque |
application/xml+jinja | xml+django xml+jinja |
application/xml+lasso | xml+lasso |
application/xml+mako | xml+mako |
application/xml+myghty | xml+myghty |
application/xml+php | xml+php |
application/xml+ruby | xml+erb xml+ruby |
application/xml+smarty | xml+smarty |
application/xml+spitfire | xml+cheetah xml+spitfire |
application/xml+velocity | xml+velocity |
application/xml-dtd | dtd |
application/xquery | xq xql xqm xquery xqy |
application/xsl+xml | xsl |
application/xslt+xml | xslt |
image/svg+xml | svg |
image/x-icon | ico |
model/vrml | vrml wrl |
text/actionscript | actionscript3 as3 |
text/actionscript3 | actionscript as |
text/coffeescript | coffee-script coffeescript |
text/css | css |
text/css+genshi | css+genshi css+genshitext |
text/css+jinja | css+django css+jinja |
text/css+lasso | css+lasso |
text/css+mako | css+mako |
text/css+myghty | css+myghty |
text/css+php | css+php |
text/css+ruby | css+erb css+ruby |
text/css+smarty | css+smarty |
text/gettext | po pot |
text/haxe | haXe hx |
text/html | htm |
text/html+evoque | html+evoque |
text/html+genshi | html+genshi html+kid |
text/html+jinja | html+django html+jinja |
text/html+mako | html+mako |
text/html+myghty | html+myghty |
text/html+ruby | html+erb html+ruby rhtml |
text/html+smarty | html+smarty |
text/html+spitfire | html+cheetah html+spitfire |
text/html+velocity | html+velocity |
text/idl | idl |
text/javascript | javascript js |
text/javascript+genshi | javascript+genshi javascript+genshitext js+genshi js+genshitext |
text/javascript+jinja | javascript+django javascript+jinja js+django js+jinja |
text/javascript+lasso | javascript+lasso js+lasso |
text/javascript+mako | javascript+mako js+mako |
text/javascript+mygthy | javascript+myghty js+myghty |
text/javascript+php | javascript+php js+php |
text/javascript+ruby | javascript+erb javascript+ruby js+erb js+ruby |
text/javascript+smarty | javascript+smarty js+smarty |
text/javascript+spitfire | javascript+cheetah javascript+spitfire js+cheetah js+spitfire |
text/livescript | live-script livescript |
text/matlab | matlab |
text/octave | octave |
text/plain | AUTHORS COPYING ChangeLog INSTALL README RELEASE TXT text txt |
text/prs.fallenstein.rst | rest restructuredtext rst |
text/scilab | scilab |
text/smali | smali |
text/troff | groff man nroff |
text/x-abap | abap |
text/x-ada | ada ada95ada2005 adb ads |
text/x-apacheconf | aconf apache apacheconf |
text/x-asm | asm |
text/x-asp | asp |
text/x-aspectj | aspectj |
text/x-asymptote | asy asymptote |
text/x-autohotkey | ahk |
text/x-autoit | Autoit autoit |
text/x-bbcode | bbcode |
text/x-bmx | blitzmax bmax |
text/x-boo | boo |
text/x-c++hdr | H HH c++hdr hh hpp |
text/x-c++src | C C++ CC c++ c++src cc cpp |
text/x-c-objdump | c-objdump |
text/x-ceylon | ceylon |
text/x-chdr | chdr h |
text/x-cmake | cmake |
text/x-cobol | cobol |
text/x-common-lisp | cl common-lisp |
text/x-coq | coq |
text/x-cpp-objdump | c++-objdumb cpp-objdump cxx-objdump |
text/x-crocsrc | croc |
text/x-csharp | C# c# cs csharp |
text/x-csrc | c csrc xs |
text/x-cuda | cu cuda |
text/x-d-objdump | d-objdump |
text/x-dart | dart |
text/x-dg | dg |
text/x-diff | patch |
text/x-dsrc | d |
text/x-dylan | dylan |
text/x-dylan-console | dylan-console dylan-repl |
text/x-dylan-lid | dylan-lid lid |
text/x-ecsrc | ec |
text/x-eiffel | e eiffel |
text/x-elisp | el elisp |
text/x-elixir | elixir ex exs |
text/x-elixir-shellsession | iex |
text/x-erl-shellsession | erl |
text/x-erlang | erlang |
text/x-factor | factor |
text/x-fancysrc | fancy fy |
text/x-felix | felix flx |
text/x-fortran | f fortran |
text/x-fsharp | fsharp |
text/x-gas | gas |
text/x-genshi | genshitext |
text/x-gherkin | Cucumber Gherkin cucumber gherkin |
text/x-glslsrc | glsl |
text/x-gnuplot | gnuplot |
text/x-gooddata-cl | gooddata-cl |
text/x-gosrc | go |
text/x-gosu | gosu |
text/x-gosu-template | gst |
text/x-groovy | groovy |
text/x-haml | HAML haml |
text/x-haskell | haskell hs |
text/x-idl | ice |
text/x-inf | inf |
text/x-ini | cfg ini |
text/x-iokesrc | ik ioke |
text/x-iosrc | io |
text/x-irclog | irc |
text/x-jade | JADE jade |
text/x-java | java |
text/x-java-properties | properties |
text/x-jbst | Duel Engine Duel View JBST JsonML+BST duel jbst |
text/x-kconfig | kconfig kernel-config linux-config menuconfig |
text/x-koka | koka |
text/x-kotlin | kotlin |
text/x-lasso | lasso lassoscript |
text/x-latex | latex tex |
text/x-lighttpd-conf | lighttpd lighty |
text/x-literate-haskell | lhs literate-haskell |
text/x-llvm | llvm |
text/x-logos | logos |
text/x-logtalk | logtalk |
text/x-m4 | m4 |
text/x-mail | mail |
text/x-makefile | GNUMakefile Makefile bsdmake make makefile mf mk |
text/x-minidsrc | minid |
text/x-modelica | modelica |
text/x-modula2 | m2 modula2 |
text/x-monkey | monkey |
text/x-moocode | moocode |
text/x-mysql | mysql |
text/x-nasm | nasm |
text/x-nemerle | nemerle |
text/x-newspeak | newspeak |
text/x-nginx-conf | nginx |
text/x-nimrod | nim nimrod |
text/x-nsis | nsh nsi nsis |
text/x-objc | m mm |
text/x-objdump | objdump |
text/x-objective-c | obj-c objc objective-c objectivec |
text/x-objective-c++ | obj-c++ objc++ objective-c++ objectivec++ |
text/x-objective-j | obj-j objective-j objectivej objj |
text/x-ocaml | ml mli ocaml |
text/x-ooc | ooc |
text/x-opa | opa |
text/x-pascal | delphi objectpascal pas pascal |
text/x-patch | diff udiff |
text/x-perl | PL pm |
text/x-php | php php3 php4 php5 |
text/x-plpgsql | plpgsql |
text/x-postgresql | postgres postgresql |
text/x-postgresql-psql | postgres-console postgresql-console psql |
text/x-povray | pov |
text/x-powershell | posh powershell ps1 |
text/x-prolog | prolog |
text/x-psp | psp |
text/x-pyrex | pyrex |
text/x-python-doctest | pycon |
text/x-python-traceback | pytb |
text/x-python3-traceback | py3tb |
text/x-r-doc | rd |
text/x-r-profile | r s splus |
text/x-rebol | rebol |
text/x-rfc | rfc |
text/x-robotframework | RobotFramework robotframework |
text/x-rpm-spec | spec |
text/x-ruby-shellsession | irb rbcon |
text/x-rustsrc | rust |
text/x-sass | SASS sass |
text/x-scala | scala |
text/x-scaml | SCAML scaml |
text/x-scss | scss |
text/x-smalltalk | smalltalk squeak |
text/x-snobol | snobol |
text/x-sourcepawn | sp |
text/x-sql | sql |
text/x-sqlite3-console | sqlite3 |
text/x-squidconf | squid squid.conf squidconf |
text/x-systemverilog | sv systemverilog |
text/x-tea | tea |
text/x-textile | textile txtl |
text/x-trac-wiki | moin trac-wiki |
text/x-typescript | ts |
text/x-vala | vala vapi |
text/x-vba | bas vb vb.net vba vbnet |
text/x-verilog | v verilog |
text/x-vhdl | vhd vhdl |
text/x-vim | vim |
text/x-windows-registry | registry |
text/x-xtend | xtend |
text/x-yaml | yaml |
text/x-zsh | zsh |
Note 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.
In 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.
HTML 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.
If mimetype such as 'svn:mime-type' is set to 'text/plain', there is no coloring even if file is known type like 'java'.
List of Languages Supported, by Highlighter
This list is only indicative.
SilverCity | Enscript | Pygments | |
---|---|---|---|
Ada | ✓ | ||
Asm | ✓ | ||
Apache Conf | ✓ | ||
ASP | ✓ | ✓ | |
C | ✓ | ✓ | ✓ |
C# | ✓ (1) | ✓ | |
C++ | ✓ | ✓ | ✓ |
CMake | ? | ? | ✓ |
Java | ✓ (2) | ✓ | ✓ |
Awk | ✓ | ||
Boo | ✓ | ||
CSS | ✓ | ✓ | |
Python Doctests | ✓ | ||
Diff | ✓ | ✓ | |
Eiffel | ✓ | ||
Elisp | ✓ | ||
Fortran | ✓ (1) | ✓ | |
Haskell | ✓ | ✓ | |
Genshi | ✓ | ||
HTML | ✓ | ✓ | ✓ |
IDL | ✓ | ||
INI | ✓ | ||
Javascript | ✓ | ✓ | ✓ |
Lua | ✓ | ||
m4 | ✓ | ||
Makefile | ✓ | ✓ | |
Mako | ✓ | ||
Matlab (3) | ✓ | ✓ | |
Mygthy | ✓ | ||
Objective-C | ✓ | ✓ | |
OCaml | ✓ | ||
Pascal | ✓ | ✓ | |
Perl | ✓ | ✓ | ✓ |
PHP | ✓ | ✓ | |
PSP | ✓ | ||
Pyrex | ✓ | ||
Python | ✓ | ✓ | ✓ |
Ruby | ✓ | ✓ (1) | ✓ |
Scheme | ✓ | ✓ | |
Shell | ✓ | ✓ | |
Smarty | ✓ | ||
SQL | ✓ | ✓ | ✓ |
Troff | ✓ | ✓ | |
TCL | ✓ | ||
Tex | ✓ | ✓ | |
Verilog | ✓ (2) | ✓ | |
VHDL | ✓ | ||
Visual Basic | ✓ | ✓ | |
VRML | ✓ | ||
XML | ✓ | ✓ |
(1) Not included in the Enscript distribution. Additional highlighting rules can be obtained for Ruby, C#, Fortran 90x/2003
(2) since Silvercity 0.9.7 released on 2006-11-23
(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 [mimeviewer] section of trac.ini.
Extra Software
- 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/
See also: WikiProcessors, WikiFormatting, TracWiki, TracBrowser