ソースコードのシンタックスカラーリング
Trac は wiki プロセッサ ブロック内の Wiki 形式のテキストと リポジトリブラウザ での、ソースコードの言語特有のシンタックスハイライトに対応しています。
Trac では色付けを行うために、とても多くのプログラミング言語に対応している外部ライブラリを使用しています。
現在、 Trac は以下にあげるパッケージを 1 つ以上使用して、シンタックスハイライトを実現しています:
- Pygments 最も推奨するシステムです。というのもカバーしているプログラミング言語、構造化テキストが多いこととサポート体制が活発であるからです
- GNU Enscript 通常 UNIX で利用できますが、 Windows ではサポートされていません
- SilverCity レガシーなシステムです。いくつかのバージョンには 問題があります
シンタックスカラーリングを有効にするには、これらのパッケージのどれか 1 つまたは 1 つ以上をインストールするだけです ( 下記の その他のソフトウェア を参照 ) もし、これらのパッケージの中で適用できるものがなければ、 Trac はプレーンテキストとしてデータを表示します。
Pygments について
Trac 0.11 以降で、 pygments はデフォルトのハイライトパッケージとなりました。ハイライト用のライブラリがピュアな Python コードで書かれていて、とても速く、拡張しやすく ドキュメントが豊富です 。
Pygments のデフォルトのスタイルは、 trac.ini の mime-viewer セクションで指定できます。デフォルトのスタイルは、 個人設定のシンタックスハイライトタブ 上のスタイルを設定することで、オーバーライドされます。
Pygments の構文解析エンジンが対応するリストは毎週のように更新されています。以下のリストが古い可能性は非常に高いです。 正確には supported lexers のページを参照してください。
対応しているシンタックスハイライト
対応している MIME タイプ
| MIME タイプ | WikiProcessors |
|---|---|
| application/msword | doc dot |
| application/pdf | pdf |
| application/postscript | ps |
| application/rss+xml | rss |
| application/rtf | rtf |
| application/x-befunge | befunge |
| application/x-brainfuck | bf brainfuck |
| application/x-clojure | clj clojure |
| application/x-csh | csh tcsh |
| application/x-cython | cython pyx |
| application/x-dos-batch | bat |
| application/x-evoque | evoque |
| application/x-httpd-php5 | html+php |
| application/x-jinja | django jinja |
| application/x-jsp | jsp |
| application/x-kid | genshi kid xml+genshi xml+kid |
| application/x-lua | lua |
| application/x-mako | mako |
| application/x-myghty | myghty |
| application/x-perl | perl pl |
| application/x-pygments-tokens | raw |
| application/x-python | py python |
| application/x-python3 | py3 python3 |
| application/x-ruby | rb ruby |
| application/x-ruby-templating | erb |
| application/x-scheme | scheme scm |
| application/x-shell-session | console |
| application/x-shellscript | bash sh |
| application/x-smarty | smarty |
| application/x-spitfire | cheetah spitfire |
| application/x-tcl | tcl |
| application/x-troff | roff troff |
| application/x-yaml | yml |
| application/xhtml+xml | html |
| application/xml+evoque | xml+evoque |
| application/xml+jinja | xml+django xml+jinja |
| 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/xsl+xml | xsl |
| application/xslt+xml | xml xslt |
| image/svg+xml | svg |
| image/x-icon | ico |
| model/vrml | vrml wrl |
| text/R | r s splus |
| text/actionscript | actionscript actionscript3 as as3 |
| text/css | css |
| text/css+genshi | css+genshi css+genshitext |
| text/css+jinja | css+django css+jinja |
| 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 |
| 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/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+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/matlab | matlab octave |
| text/plain | AUTHORS COPYING ChangeLog INSTALL README RELEASE TXT text txt |
| text/prs.fallenstein.rst | rest restructuredtext rst |
| text/troff | groff man nroff |
| text/x-abap | abap |
| text/x-ada | ada adb ads |
| text/x-apacheconf | aconf apache apacheconf |
| text/x-asm | asm |
| text/x-asp | asp |
| text/x-awk | awk |
| text/x-bbcode | bbcode |
| 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-chdr | chdr h |
| text/x-common-lisp | cl common-lisp |
| text/x-cpp-objdump | c++-objdumb cpp-objdump cxx-objdump |
| text/x-csharp | C# c# cs csharp |
| text/x-csrc | c csrc xs |
| text/x-d-objdump | d-objdump |
| text/x-diff | patch |
| text/x-dsrc | d |
| text/x-dylan | dylan |
| text/x-eiffel | e eiffel |
| text/x-elisp | el elisp |
| text/x-erl-shellsession | erl |
| text/x-erlang | erlang |
| text/x-fortran | f fortran |
| text/x-gas | gas |
| text/x-genshi | genshitext |
| text/x-glslsrc | glsl |
| text/x-gnuplot | gnuplot |
| text/x-haskell | haskell hs |
| text/x-idl | ice idl |
| text/x-inf | inf |
| text/x-ini | cfg ini |
| text/x-iosrc | io |
| text/x-irclog | irc |
| text/x-java | java |
| text/x-ksh | ksh |
| text/x-latex | latex tex |
| text/x-lighttpd-conf | lighttpd lighty |
| text/x-literate-haskell | lhs literate-haskell |
| text/x-llvm | llvm |
| 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-moocode | moocode |
| text/x-mysql | mysql |
| text/x-nasm | nasm |
| text/x-newspeak | newspeak |
| text/x-nginx-conf | nginx |
| text/x-objc | m mm |
| text/x-objdump | objdump |
| text/x-objective-c | obj-c objc objective-c objectivec |
| text/x-ocaml | ml mli ocaml |
| 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-povray | pov |
| 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-rebol | rebol |
| text/x-rfc | rfc |
| text/x-ruby-shellsession | irb rbcon |
| text/x-scala | scala |
| text/x-smalltalk | smalltalk squeak |
| text/x-sql | sql |
| text/x-sqlite3-console | sqlite3 |
| text/x-squidconf | squid squid.conf squidconf |
| text/x-textile | textile txtl |
| text/x-trac-wiki | moin trac-wiki |
| 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-yaml | yaml |
| text/x-zsh | zsh |
Note: 高度なコンテンツはシンタックスハイライトの代わりに直接レンダリングされるかもしれません。これはインストールされている予備のパッケージ及び設定したコンポーネントによって決まります。例えば、text/x-rst ドキュメントでは、docutils がインストールされていて、trac.mimeview.rst.ReStructuredTextRenderer が無効になっておらず、他にシンタックスハイライトが存在するような場合、docutils を通してレンダリングされます。
同様の方法で、 MIME タイプ text/x-trac-wiki のドキュメントは Trac Wiki フォーマットを使ってレンダリングされます。ただし、 trac.mimeview.api.WikiTextRenderer コンポーネントは無効とされます。
HTML ドキュメントは render_unsafe_html が TracIni で有効に設定されている場合に限り、直接レンダリングされます。 (ドキュメントがどこからくるかによって異なるセキュリティ上の懸念がある場合、これらの設定は、複数のセクションに存在します)。もし HTML ドキュメントがレンダリングを行わず、シンタックスハイライトなるよう保証したいのであれば、 MIME タイプ text/xml を使用してください。
'svn:mime-type' 属性が 'text/plain' のように MIME タイプで設定されている場合、例え 'java' で書かれたファイルであっても色づけされません。
ハイライトパッケージがサポートする言語
このリストはほんの一例です:
| 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) Enscript のパッケージには含まれていません。 以下のハイライトルールを追加することが可能です。 Ruby, C#, Fortran 90x/2003
(2) Silvercity 0.9.7 は 2006-11-23 にリリースされました。
(3) デフォルトで、 .m ファイルは Objective-C のファイルだと解釈されます。 .m ファイルを MATLAB ファイルとして扱うためには、 "text/matlab:m" を trac.ini の [mimeviewer] セクション 内、 "mime_map" の設定に追加してください。
その他のソフトウェア
- 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
