Version 2 (modified by 14 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/json-object | json-object |
application/kal | kal |
application/ld+json | json-ld jsonld |
application/msword | doc dot |
application/pdf | pdf |
application/postscript | postscr postscript ps |
application/rss+xml | rss |
application/rtf | rtf |
application/sparql-query | sparql |
application/vnd.wolfram.cdf | mathematica mma nb |
application/x-awk | awk gawk mawk nawk |
application/x-befunge | befunge |
application/x-brainfuck | bf brainfuck |
application/x-chaiscript | chai chaiscript |
application/x-clojure | clj clojure |
application/x-clojurescript | cljs clojurescript |
application/x-coldfusion | cfm |
application/x-csh | csh tcsh |
application/x-cython | cython pyrex pyx |
application/x-dos-batch | bat batch cmd dos dosbatch winbatch |
application/x-ecl | ecl |
application/x-elisp | elisp emacs emacs-lisp |
application/x-evoque | evoque |
application/x-fantom | fan |
application/x-fish | fish fishshell |
application/x-forth | forth |
application/x-gooddata-maql | maql |
application/x-httpd-lasso[89] | html+lasso |
application/x-httpd-php5 | html+php |
application/x-hy | hylang |
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-perl6 | perl6 pl6 |
application/x-pygments-tokens | raw |
application/x-pypylog | pypy pypylog |
application/x-python | py python sage |
application/x-python3 | py3 python3 |
application/x-qt.qbs+qml | qbs qml |
application/x-racket | racket rkt |
application/x-ruby | duby rb ruby |
application/x-ruby-templating | erb |
application/x-sas | sas |
application/x-scheme | scheme scm |
application/x-sh-session | console shell-session |
application/x-shen | shen |
application/x-smarty | smarty |
application/x-spitfire | cheetah spitfire |
application/x-ssp | ssp |
application/x-standardml | sml |
application/x-stata | do stata |
application/x-tcl | tcl |
application/x-terraform | terraform tf |
application/x-thrift | thrift |
application/x-troff | roff troff |
application/x-turtle | turtle |
application/x-twig | twig |
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 | actionscript as |
text/actionscript3 | actionscript3 as3 |
text/basic | basic qbasic |
text/coffeescript | coffee 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/html | htm |
text/html+evoque | html+evoque |
text/html+genshi | html+genshi html+kid |
text/html+jinja | html+django html+jinja htmldjango |
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 htmlcheetah |
text/html+twig | html+twig |
text/html+velocity | html+velocity |
text/idl | idl |
text/inf | cfg dosini ini |
text/ipf | igor igorpro |
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/jsgf | jsgf |
text/juttle | juttle |
text/limbo | limbo |
text/livescript | live-script livescript |
text/matlab | matlab |
text/ncl | ncl |
text/octave | octave |
text/odin | odin |
text/plain | AUTHORS COPYING ChangeLog INSTALL README RELEASE TXT text txt |
text/prs.fallenstein.rst | rest restructuredtext rst |
text/rsl | rsl |
text/rust | rs rust |
text/scilab | scilab |
text/smali | smali |
text/supercollider | sc supercollider |
text/swig | swig |
text/troff | groff man nroff |
text/unicon | unicon |
text/x-abap | abap |
text/x-abnf | abnf |
text/x-ada | ada ada2005 ada95 adb ads |
text/x-agda | agda |
text/x-alloy | alloy |
text/x-ambienttalk | ambienttalk ambienttalk/2 at |
text/x-apacheconf | aconf apache apacheconf |
text/x-arduino | arduino |
text/x-asp | asp |
text/x-aspectj | aspectj |
text/x-asymptote | asy asymptote |
text/x-autohotkey | ahk autohotkey |
text/x-autoit | autoit |
text/x-bb | b3d blitzbasic bplus |
text/x-bbcode | bbcode |
text/x-bibtex | bib bibtex |
text/x-bmx | blitzmax bmax |
text/x-bnf | bnf |
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-cirru | cirru |
text/x-clay | clay |
text/x-cmake | cmake |
text/x-cobol | cobol |
text/x-common-lisp | cl common-lisp lisp |
text/x-component-pascal | componentpascal cp |
text/x-coq | coq |
text/x-cpp-objdump | c++-objdumb cpp-objdump cxx-objdump |
text/x-crocsrc | croc |
text/x-cryptol | cry cryptol |
text/x-crystal | cr crystal |
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-dasm16 | dasm16 |
text/x-dg | dg |
text/x-diff | patch |
text/x-dockerfile-config | docker dockerfile |
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-earl-grey | earl-grey earlgrey eg |
text/x-easytrieve | easytrieve |
text/x-ebnf | ebnf |
text/x-ecsrc | ec |
text/x-eiffel | e eiffel |
text/x-elisp | el |
text/x-elixir | elixir ex exs |
text/x-elixir-shellsession | iex |
text/x-elm | elm |
text/x-erl-shellsession | erl |
text/x-erlang | erlang |
text/x-ezhil | ezhil |
text/x-factor | factor |
text/x-fancysrc | fancy fy |
text/x-felix | felix flx |
text/x-flatline | flatline |
text/x-fortran | f fortran |
text/x-freefem | freefem |
text/x-fsharp | fsharp |
text/x-gas | asm gas |
text/x-genshi | genshitext |
text/x-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 |
text/x-handlebars-template | html+handlebars |
text/x-haskell | haskell hs |
text/x-hlsl | hlsl |
text/x-hsail | hsa hsail |
text/x-hx | haxe hx hxsl |
text/x-idl | ice |
text/x-idris | idr idris |
text/x-inf | inf |
text/x-iokesrc | ik ioke |
text/x-iosrc | io |
text/x-irclog | irc |
text/x-isabelle | isabelle |
text/x-j | j |
text/x-jade | jade pug |
text/x-java | java |
text/x-java-properties | jproperties properties |
text/x-jbst | duel jbst jsonml+bst |
text/x-jcl | jcl |
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-lean | lean |
text/x-less-css | less |
text/x-lighttpd-conf | lighttpd lighty |
text/x-literate-agda | lagda literate-agda |
text/x-literate-cryptol | lcry lcryptol literate-cryptol |
text/x-literate-haskell | lhaskell lhs literate-haskell |
text/x-literate-idris | lidr lidris literate-idris |
text/x-llvm | llvm |
text/x-logos | logos |
text/x-logtalk | logtalk |
text/x-lsl | lsl |
text/x-m4 | m4 |
text/x-mail | mail |
text/x-makefile | GNUMakefile Makefile bsdmake make makefile mf mk |
text/x-markdown | md |
text/x-mask | mask |
text/x-minidsrc | minid |
text/x-modelica | modelica |
text/x-modula2 | m2 modula2 |
text/x-monkey | monkey |
text/x-moocode | moo moocode |
text/x-mql | mq4 mq5 mql mql4 mql5 |
text/x-mysql | mysql |
text/x-nasm | nasm |
text/x-nasm-objdump | objdump-nasm |
text/x-nemerle | nemerle |
text/x-nescsrc | nesc |
text/x-newspeak | newspeak |
text/x-nginx-conf | nginx nginx-conf |
text/x-nim | nim nimrod |
text/x-nix | nix nixos |
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-parasail | parasail |
text/x-pascal | delphi objectpascal pas pascal |
text/x-patch | diff udiff |
text/x-pawn | pawn |
text/x-perl | PL pm |
text/x-php | php php3 php4 php5 |
text/x-pig | pig |
text/x-pike | pike |
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 psm1 |
text/x-prolog | prolog |
text/x-psp | psp |
text/x-python-doctest | pycon python-doctest |
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-red-system | red red/system |
text/x-rexx | arexx rexx |
text/x-rfc | rfc |
text/x-robotframework | robotframework |
text/x-rpm-spec | spec |
text/x-rql | rql |
text/x-ruby-shellsession | irb rbcon |
text/x-sarl | sarl |
text/x-sass | sass |
text/x-scala | scala |
text/x-scaml | scaml |
text/x-scss | scss |
text/x-shellscript | bash ksh sh shell zsh |
text/x-slim | slim |
text/x-sls | salt sls yaml+jinja |
text/x-smalltalk | smalltalk squeak st |
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-swift | swift |
text/x-systemverilog | sv systemverilog |
text/x-tasm | tasm |
text/x-tea | tea |
text/x-teratermmacro | teraterm teratermmacro ttl |
text/x-textile | textile txtl |
text/x-todo | todotxt |
text/x-trac-wiki | moin trac-wiki |
text/x-tsql | t-sql tsql |
text/x-typescript | ts typescript |
text/x-typoscript | typoscript |
text/x-vala | vala vapi |
text/x-vba | bas vb vb.net vba vbnet |
text/x-vclsnippet | vclsnippet vclsnippets |
text/x-vclsrc | vcl |
text/x-verilog | v verilog |
text/x-vhdl | vhd vhdl |
text/x-vim | vim |
text/x-whiley | whiley |
text/x-windows-registry | registry |
text/x-x10 | x10 xten |
text/x-xtend | xtend |
text/x-yaml | yaml |
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
- 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