wiki:TracSyntaxColoring

Version 3 (modified by trac, 13 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 TypesWikiProcessors
application/atom+xmlxml
application/jsonjson
application/msworddoc dot
application/pdfpdf
application/postscriptpostscript ps
application/rss+xmlrss
application/rtfrtf
application/x-awkawk gawk mawk nawk
application/x-befungebefunge
application/x-brainfuckbf brainfuck
application/x-clojureclj clojure
application/x-coldfusioncfm
application/x-cshcsh tcsh
application/x-cythoncython pyx
application/x-dos-batchbat batch cmd dos
application/x-eclecl
application/x-evoqueevoque
application/x-fantomfan
application/x-gooddata-maqlmaql
application/x-httpd-lasso[89]html+lasso
application/x-httpd-php5html+php
application/x-hybrishy hybris
application/x-jinjadjango jinja
application/x-jspjsp
application/x-juliajl julia
application/x-kidgenshi kid xml+genshi xml+kid
application/x-lualua
application/x-makomako
application/x-masonmason
application/x-moonscriptmoon moonscript
application/x-myghtymyghty
application/x-newlispnewlisp
application/x-openedgeabl openedge progress
application/x-perlperl pl
application/x-pygments-tokensraw
application/x-pypylogpypy pypylog
application/x-pythonpy python sage
application/x-python3py3 python3
application/x-qmlQt Meta Language Qt modeling Language qml
application/x-racketracket rkt
application/x-rubyduby rb ruby
application/x-ruby-templatingerb
application/x-schemescheme scm
application/x-sh-sessionshell-session
application/x-shell-sessionconsole
application/x-shellscriptbash ksh sh
application/x-smartysmarty
application/x-spitfirecheetah spitfire
application/x-sspssp
application/x-standardmlsml
application/x-tcltcl
application/x-troffroff troff
application/x-urbiscripturbiscript
application/x-yamlyml
application/xhtml+xmlhtml
application/xml+evoquexml+evoque
application/xml+jinjaxml+django xml+jinja
application/xml+lassoxml+lasso
application/xml+makoxml+mako
application/xml+myghtyxml+myghty
application/xml+phpxml+php
application/xml+rubyxml+erb xml+ruby
application/xml+smartyxml+smarty
application/xml+spitfirexml+cheetah xml+spitfire
application/xml+velocityxml+velocity
application/xml-dtddtd
application/xqueryxq xql xqm xquery xqy
application/xsl+xmlxsl
application/xslt+xmlxslt
image/svg+xmlsvg
image/x-iconico
model/vrmlvrml wrl
text/actionscriptactionscript3 as3
text/actionscript3actionscript as
text/coffeescriptcoffee-script coffeescript
text/csscss
text/css+genshicss+genshi css+genshitext
text/css+jinjacss+django css+jinja
text/css+lassocss+lasso
text/css+makocss+mako
text/css+myghtycss+myghty
text/css+phpcss+php
text/css+rubycss+erb css+ruby
text/css+smartycss+smarty
text/gettextpo pot
text/haxehaXe hx
text/htmlhtm
text/html+evoquehtml+evoque
text/html+genshihtml+genshi html+kid
text/html+jinjahtml+django html+jinja
text/html+makohtml+mako
text/html+myghtyhtml+myghty
text/html+rubyhtml+erb html+ruby rhtml
text/html+smartyhtml+smarty
text/html+spitfirehtml+cheetah html+spitfire
text/html+velocityhtml+velocity
text/idlidl
text/javascriptjavascript js
text/javascript+genshijavascript+genshi javascript+genshitext js+genshi js+genshitext
text/javascript+jinjajavascript+django javascript+jinja js+django js+jinja
text/javascript+lassojavascript+lasso js+lasso
text/javascript+makojavascript+mako js+mako
text/javascript+mygthyjavascript+myghty js+myghty
text/javascript+phpjavascript+php js+php
text/javascript+rubyjavascript+erb javascript+ruby js+erb js+ruby
text/javascript+smartyjavascript+smarty js+smarty
text/javascript+spitfirejavascript+cheetah javascript+spitfire js+cheetah js+spitfire
text/livescriptlive-script livescript
text/matlabmatlab
text/octaveoctave
text/plainAUTHORS COPYING ChangeLog INSTALL README RELEASE TXT text txt
text/prs.fallenstein.rstrest restructuredtext rst
text/scilabscilab
text/smalismali
text/troffgroff man nroff
text/x-abapabap
text/x-adaada ada95ada2005 adb ads
text/x-apacheconfaconf apache apacheconf
text/x-asmasm
text/x-aspasp
text/x-aspectjaspectj
text/x-asymptoteasy asymptote
text/x-autohotkeyahk
text/x-autoitAutoit autoit
text/x-bbcodebbcode
text/x-bmxblitzmax bmax
text/x-booboo
text/x-c++hdrH HH c++hdr hh hpp
text/x-c++srcC C++ CC c++ c++src cc cpp
text/x-c-objdumpc-objdump
text/x-ceylonceylon
text/x-chdrchdr h
text/x-cmakecmake
text/x-cobolcobol
text/x-common-lispcl common-lisp
text/x-coqcoq
text/x-cpp-objdumpc++-objdumb cpp-objdump cxx-objdump
text/x-crocsrccroc
text/x-csharpC# c# cs csharp
text/x-csrcc csrc xs
text/x-cudacu cuda
text/x-d-objdumpd-objdump
text/x-dartdart
text/x-dgdg
text/x-diffpatch
text/x-dsrcd
text/x-dylandylan
text/x-dylan-consoledylan-console dylan-repl
text/x-dylan-liddylan-lid lid
text/x-ecsrcec
text/x-eiffele eiffel
text/x-elispel elisp
text/x-elixirelixir ex exs
text/x-elixir-shellsessioniex
text/x-erl-shellsessionerl
text/x-erlangerlang
text/x-factorfactor
text/x-fancysrcfancy fy
text/x-felixfelix flx
text/x-fortranf fortran
text/x-fsharpfsharp
text/x-gasgas
text/x-genshigenshitext
text/x-gherkinCucumber Gherkin cucumber gherkin
text/x-glslsrcglsl
text/x-gnuplotgnuplot
text/x-gooddata-clgooddata-cl
text/x-gosrcgo
text/x-gosugosu
text/x-gosu-templategst
text/x-groovygroovy
text/x-hamlHAML haml
text/x-haskellhaskell hs
text/x-idlice
text/x-infinf
text/x-inicfg ini
text/x-iokesrcik ioke
text/x-iosrcio
text/x-irclogirc
text/x-jadeJADE jade
text/x-javajava
text/x-java-propertiesproperties
text/x-jbstDuel Engine Duel View JBST JsonML+BST duel jbst
text/x-kconfigkconfig kernel-config linux-config menuconfig
text/x-kokakoka
text/x-kotlinkotlin
text/x-lassolasso lassoscript
text/x-latexlatex tex
text/x-lighttpd-conflighttpd lighty
text/x-literate-haskelllhs literate-haskell
text/x-llvmllvm
text/x-logoslogos
text/x-logtalklogtalk
text/x-m4m4
text/x-mailmail
text/x-makefileGNUMakefile Makefile bsdmake make makefile mf mk
text/x-minidsrcminid
text/x-modelicamodelica
text/x-modula2m2 modula2
text/x-monkeymonkey
text/x-moocodemoocode
text/x-mysqlmysql
text/x-nasmnasm
text/x-nemerlenemerle
text/x-newspeaknewspeak
text/x-nginx-confnginx nginx-conf
text/x-nimrodnim nimrod
text/x-nsisnsh nsi nsis
text/x-objcm mm
text/x-objdumpobjdump
text/x-objective-cobj-c objc objective-c objectivec
text/x-objective-c++obj-c++ objc++ objective-c++ objectivec++
text/x-objective-jobj-j objective-j objectivej objj
text/x-ocamlml mli ocaml
text/x-oocooc
text/x-opaopa
text/x-pascaldelphi objectpascal pas pascal
text/x-patchdiff udiff
text/x-perlPL pm
text/x-phpphp php3 php4 php5
text/x-plpgsqlplpgsql
text/x-postgresqlpostgres postgresql
text/x-postgresql-psqlpostgres-console postgresql-console psql
text/x-povraypov
text/x-powershellposh powershell ps1
text/x-prologprolog
text/x-psppsp
text/x-pyrexpyrex
text/x-python-doctestpycon python-doctest
text/x-python-tracebackpytb
text/x-python3-tracebackpy3tb
text/x-r-docrd
text/x-r-profiler s splus
text/x-rebolrebol
text/x-rfcrfc
text/x-robotframeworkRobotFramework robotframework
text/x-rpm-specspec
text/x-ruby-shellsessionirb rbcon
text/x-rustsrcrust
text/x-sassSASS sass
text/x-scalascala
text/x-scamlSCAML scaml
text/x-scssscss
text/x-smalltalksmalltalk squeak
text/x-snobolsnobol
text/x-sourcepawnsp
text/x-sqlsql
text/x-sqlite3-consolesqlite3
text/x-squidconfsquid squid.conf squidconf
text/x-systemverilogsv systemverilog
text/x-teatea
text/x-textiletextile txtl
text/x-trac-wikimoin trac-wiki
text/x-typescriptts
text/x-valavala vapi
text/x-vbabas vb vb.net vba vbnet
text/x-verilogv verilog
text/x-vhdlvhd vhdl
text/x-vimvim
text/x-windows-registryregistry
text/x-xtendxtend
text/x-yamlyaml
text/x-zshzsh

List of Languages Supported, by Highlighter

This list is only indicative.

SilverCity Enscript Pygments
Ada
Asm
Apache Conf
ASP
C
C# (1)
C++
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


See also: WikiProcessors, WikiFormatting, TracWiki, TracBrowser