Version 3 (modified by 11 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/ld+json | json-ld jsonld |
application/msword | doc |
application/pdf | pdf |
application/pgp-signature | asc pem |
application/postscript | postscr postscript ps |
application/rss+xml | rss |
application/rtf | rtf |
application/sparql-query | sparql |
application/toml | toml |
application/vnd.wolfram.mathematica.package | mathematica mma nb |
application/x-awk | awk gawk mawk nawk |
application/x-befunge | befunge |
application/x-brainfuck | bf brainfuck |
application/x-coldfusion | cfm |
application/x-csh | csh tcsh |
application/x-dos-batch | bat batch cmd dos dosbatch winbatch |
application/x-ecl | ecl |
application/x-evoque | evoque |
application/x-fantom | fan |
application/x-fish | fish fishshell |
application/x-forth | forth |
application/x-jinja | django jinja |
application/x-jsp | jsp |
application/x-kid | genshi kid xml+genshi xml+kid |
application/x-mako | mako |
application/x-mason | mason |
application/x-myghty | myghty |
application/x-ndjson | json json-object |
application/x-openscad | openscad |
application/x-php | html+php |
application/x-prql | prql |
application/x-pypylog | pypy pypylog |
application/x-qt.qbs+qml | qbs qml |
application/x-ruby-templating | erb |
application/x-shell-session | console shell-session |
application/x-smarty | smarty |
application/x-spitfire | cheetah spitfire |
application/x-ssp | ssp |
application/x-tf | hcl terraform tf |
application/x-thrift | thrift |
application/x-troff | roff troff |
application/x-twig | twig |
application/x-urbiscript | urbiscript |
application/x-www-form-urlencoded | urlencoded |
application/x-yaml | yml |
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/xsl+xml | xsl |
application/xslt+xml | xslt |
application/yang | yang |
image/svg+xml | svg |
image/x-icon | ico |
message/rfc822 | email eml |
model/vrml | vrml wrl |
multipart/related | mime |
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/dns | zone |
text/html | htm html |
text/html+evoque | html+evoque |
text/html+genshi | html+genshi html+kid |
text/html+jinja | html+django html+jinja htmldjango |
text/html+lasso | html+lasso |
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/ipf | igor igorpro |
text/jsgf | jsgf |
text/kal | kal |
text/limbo | limbo |
text/livescript | live-script livescript |
text/matlab | matlab |
text/mcfunction | mcf mcfunction |
text/mcschema | mcschema |
text/ncl | ncl |
text/octave | octave |
text/odin | odin |
text/plain | AUTHORS COPYING ChangeLog INSTALL README RELEASE TXT text txt |
text/rita | rita |
text/rsl | rsl |
text/scilab | scilab |
text/shex | shex shexc |
text/smali | smali |
text/snbt | snbt |
text/supercollider | sc supercollider |
text/swig | swig |
text/troff | groff man nroff |
text/turtle | turtle |
text/typescript-jsx | jsx react |
text/unicon | unicon |
text/vnd.tiddlywiki | tid |
text/wgsl | wgsl |
text/x-abap | abap |
text/x-abnf | abnf |
text/x-actionscript | actionscript as |
text/x-actionscript3 | actionscript3 as3 |
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-bdd | bdd |
text/x-berry | be berry |
text/x-bibtex | bib bibtex |
text/x-blueprint | blueprint |
text/x-bmx | blitzmax bmax |
text/x-bnf | bnf |
text/x-boo | boo |
text/x-c | devicetree dts |
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-carbon | carbon |
text/x-cddl | cddl |
text/x-ceylon | ceylon |
text/x-chaiscript | chai chaiscript |
text/x-chdr | chdr h |
text/x-cirru | cirru |
text/x-clay | clay |
text/x-clojure | clj clojure |
text/x-clojurescript | cljs clojurescript |
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-cplint | cplint |
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-cython | cython pyrex pyx |
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 elisp emacs emacs-lisp |
text/x-elixir | elixir ex exs |
text/x-elixir-shellsession | iex |
text/x-elm | elm |
text/x-elpi | elpi |
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 f90 fortran |
text/x-freefem | freefem |
text/x-fsharp | f# fsharp |
text/x-fstar | fstar |
text/x-futhark | futhark |
text/x-gas | asm gas |
text/x-gdscript | gd gdscript |
text/x-genshi | genshitext |
text/x-gettext | po pot |
text/x-gherkin | cucumber gherkin |
text/x-glslsrc | glsl |
text/x-gnuplot | gnuplot |
text/x-gooddata-cl | gooddata-cl |
text/x-gooddata-maql | maql |
text/x-gosrc | go golang |
text/x-gosu | gosu |
text/x-gosu-template | gst |
text/x-graphviz | dot graphviz |
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-hy | hylang |
text/x-hybris | hy hybris |
text/x-idl | ice |
text/x-idris | idr idris |
text/x-inf | inf |
text/x-ini | cfg dosini ini |
text/x-iokesrc | ik ioke |
text/x-iosrc | io |
text/x-irclog | irc |
text/x-isabelle | isabelle |
text/x-j | j |
text/x-java | java |
text/x-java-properties | jproperties properties |
text/x-javascript | javascript js |
text/x-javascript+genshi | javascript+genshi javascript+genshitext js+genshi js+genshitext |
text/x-javascript+jinja | javascript+django javascript+jinja js+django js+jinja |
text/x-javascript+lasso | javascript+lasso js+lasso |
text/x-javascript+mako | javascript+mako js+mako |
text/x-javascript+myghty | javascript+myghty js+myghty |
text/x-javascript+php | javascript+php js+php |
text/x-javascript+ruby | javascript+erb javascript+ruby js+erb js+ruby |
text/x-javascript+smarty | javascript+smarty js+smarty |
text/x-javascript+spitfire | javascript+cheetah javascript+spitfire js+cheetah js+spitfire |
text/x-jbst | duel jbst jsonml+bst |
text/x-jcl | jcl |
text/x-jslt | jslt |
text/x-julia | jl julia |
text/x-juttle | juttle |
text/x-kconfig | kconfig kernel-config linux-config menuconfig |
text/x-koka | koka |
text/x-kotlin | kotlin |
text/x-lasso | lasso lassoscript |
text/x-ldapconf | ldapconf ldaprc |
text/x-ldif | ldif |
text/x-lean3 | lean lean3 |
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-lua | lua |
text/x-m4 | m4 |
text/x-mail | mail |
text/x-makefile | GNUMakefile Makefile bsdmake make makefile mf mk |
text/x-markdown | markdown md |
text/x-mask | mask |
text/x-meson | meson meson.build |
text/x-minicript | miniscript ms |
text/x-minidsrc | minid |
text/x-modelica | modelica |
text/x-modula2 | m2 modula2 |
text/x-monkey | monkey |
text/x-moocode | moo moocode |
text/x-moonscript | moon moonscript |
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-newlisp | newlisp |
text/x-newspeak | newspeak |
text/x-nginx-conf | nginx nginx-conf |
text/x-nim | nim nimrod |
text/x-nix | nix nixos |
text/x-nodejsrepl | nodejsrepl |
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-openedge | abl openedge progress |
text/x-parasail | parasail |
text/x-pascal | delphi objectpascal pas pascal |
text/x-patch | diff udiff |
text/x-pawn | pawn |
text/x-peg | peg |
text/x-perl | PL perl pl pm |
text/x-perl6 | perl6 pl6 raku |
text/x-phix | phix |
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-explain | postgres-explain |
text/x-postgresql-psql | postgres-console postgresql-console psql |
text/x-povray | pov |
text/x-powershell | posh powershell ps1 psm1 pwsh |
text/x-prolog | prolog |
text/x-psp | psp |
text/x-ptx | ptx |
text/x-pug | jade pug |
text/x-python-doctest | pycon python-doctest |
text/x-python2 | py2 python2 |
text/x-python2-traceback | py2tb |
text/x-python3 | bazel py py3 python python3 sage starlark |
text/x-python3-traceback | py3tb pytb |
text/x-r-doc | rd |
text/x-r-source | r s splus |
text/x-racket | racket rkt |
text/x-reasonml | reason reasonml |
text/x-rebol | rebol |
text/x-red-system | red red/system |
text/x-rexx | arexx rexx |
text/x-rfc | rfc |
text/x-ride | ride |
text/x-robotframework | robotframework |
text/x-rpm-spec | spec |
text/x-rql | rql |
text/x-rst | rest restructuredtext rst |
text/x-ruby | duby rb ruby |
text/x-ruby-shellsession | irb rbcon |
text/x-rust | rs rust |
text/x-sarl | sarl |
text/x-sas | sas |
text/x-sass | sass |
text/x-scala | scala |
text/x-scaml | scaml |
text/x-scheme | scheme scm |
text/x-scss | scss |
text/x-sed | gsed sed ssed |
text/x-shellscript | bash ksh sh shell zsh |
text/x-shen | shen |
text/x-slim | slim |
text/x-smalltalk | smalltalk squeak st |
text/x-snobol | snobol |
text/x-sourcepawn | sp |
text/x-spice | spice spicelang |
text/x-sql | sql |
text/x-sqlite3-console | sqlite3 |
text/x-squidconf | squid squid.conf squidconf |
text/x-standardml | sml |
text/x-stata | do stata |
text/x-swift | swift |
text/x-systemverilog | sv systemverilog |
text/x-tasm | tasm |
text/x-tcl | tcl |
text/x-tea | tea |
text/x-teratermmacro | teraterm teratermmacro ttl |
text/x-tex | latex tex |
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-uxntal | tal uxntal |
text/x-vala | vala vapi |
text/x-vba | bas vb vba |
text/x-vbnet | lobas oobas sobas vb.net vbnet |
text/x-vclsnippet | vclsnippet vclsnippets |
text/x-vclsrc | vcl |
text/x-verifpal | verifpal |
text/x-verilog | v verilog |
text/x-vhdl | vhd vhdl |
text/x-vim | vim |
text/x-whiley | whiley |
text/x-wiki | mediawiki wikitext |
text/x-windows-registry | registry |
text/x-x10 | x10 xten |
text/x-xtend | xtend |
text/x-yaml | yaml |
text/x-yaml+jinja | salt sls yaml+jinja |
text/x-yara | yar yara |
text/xml | xml |
text/xquery | xq xql xqm xquery xqy |
text/zig | zig |
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