wiki:TracSyntaxColoring

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. Syntax coloring is provided using Pygments, which covers a wide range of programming languages and other structured texts, and is actively supported. If Pygments is not available, Trac will display the content as plain text.

About Pygments

Pygments is 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.

Pygments lexer options can be specified as WikiProcessor arguments and defaults can be set in the environment configuration.

Syntax Coloring Support

Supported languages

The list of currently supported languages can be found on the supported languages page. The list represents the languages supported in the most recent version of Pygments, so the languages actually supported in your installation could differ if you have an older version installed. The listing of supported lexers provides additional information about the default mime type to keyword mappings.

Explicit control of the mime type associated with a WikiProcessor and file extension is available through the mime_map setting. For example, 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.

If 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.

Direct Rendering

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.

Known MIME types

MIME TypesWikiProcessors
application/msworddoc dot
application/pdfpdf
application/postscriptps
application/rss+xmlrss
application/rtfrtf
application/x-befungebefunge
application/x-brainfuckbf brainfuck
application/x-clojureclj clojure
application/x-cshcsh tcsh
application/x-cythoncython pyx
application/x-dos-batchbat batch cmd dos
application/x-evoqueevoque
application/x-httpd-php5html+php
application/x-jinjadjango jinja
application/x-jspjsp
application/x-kidgenshi kid xml+genshi xml+kid
application/x-lualua
application/x-makomako
application/x-myghtymyghty
application/x-perlperl pl
application/x-pygments-tokensraw
application/x-pythonpy python
application/x-python3py3 python3
application/x-rubyrb ruby
application/x-ruby-templatingerb
application/x-schemescheme scm
application/x-shell-sessionconsole
application/x-shellscriptbash sh
application/x-smartysmarty
application/x-spitfirecheetah spitfire
application/x-tcltcl
application/x-troffroff troff
application/x-yamlyml
application/xhtml+xmlhtml
application/xml+evoquexml+evoque
application/xml+jinjaxml+django xml+jinja
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/xsl+xmlxsl
application/xslt+xmlxml xslt
image/svg+xmlsvg
image/x-iconico
model/vrmlvrml wrl
text/Rr s splus
text/actionscriptactionscript actionscript3 as as3
text/csscss
text/css+genshicss+genshi css+genshitext
text/css+jinjacss+django css+jinja
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/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/javascriptjavascript js
text/javascript+genshijavascript+genshi javascript+genshitext js+genshi js+genshitext
text/javascript+jinjajavascript+django javascript+jinja js+django js+jinja
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/matlabmatlab octave
text/plainAUTHORS COPYING ChangeLog INSTALL README RELEASE TXT text txt
text/prs.fallenstein.rstrest restructuredtext rst
text/troffgroff man nroff
text/x-abapabap
text/x-adaada adb ads
text/x-apacheconfaconf apache apacheconf
text/x-asmasm
text/x-aspasp
text/x-awkawk
text/x-bbcodebbcode
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-chdrchdr h
text/x-common-lispcl common-lisp
text/x-cpp-objdumpc++-objdumb cpp-objdump cxx-objdump
text/x-csharpC# c# cs csharp
text/x-csrcc csrc xs
text/x-d-objdumpd-objdump
text/x-diffpatch
text/x-dsrcd
text/x-dylandylan
text/x-eiffele eiffel
text/x-elispel elisp
text/x-erl-shellsessionerl
text/x-erlangerlang
text/x-fortranf fortran
text/x-gasgas
text/x-genshigenshitext
text/x-glslsrcglsl
text/x-gnuplotgnuplot
text/x-haskellhaskell hs
text/x-idlice idl
text/x-infinf
text/x-inicfg ini
text/x-iosrcio
text/x-irclogirc
text/x-javajava
text/x-kshksh
text/x-latexlatex tex
text/x-lighttpd-conflighttpd lighty
text/x-literate-haskelllhs literate-haskell
text/x-llvmllvm
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-moocodemoocode
text/x-mysqlmysql
text/x-nasmnasm
text/x-newspeaknewspeak
text/x-nginx-confnginx nginx-conf
text/x-objcm mm
text/x-objdumpobjdump
text/x-objective-cobj-c objc objective-c objectivec
text/x-ocamlml mli ocaml
text/x-pascaldelphi objectpascal pas pascal
text/x-patchdiff udiff
text/x-perlPL pm
text/x-phpphp php3 php4 php5
text/x-povraypov
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-rebolrebol
text/x-rfcrfc
text/x-ruby-shellsessionirb rbcon
text/x-scalascala
text/x-smalltalksmalltalk squeak
text/x-sqlsql
text/x-sqlite3-consolesqlite3
text/x-squidconfsquid squid.conf squidconf
text/x-textiletextile txtl
text/x-trac-wikimoin trac-wiki
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-yamlyaml
text/x-zshzsh


See also: WikiProcessors, WikiFormatting, TracWiki, TracBrowser

Last modified 10 days ago Last modified on Nov 23, 2016 10:23:12 AM