Changes between Version 1 and Version 2 of TracSyntaxColoring
- Timestamp:
- 08/21/13 19:46:14 (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracSyntaxColoring
v1 v2 ˆà 1 1 = Syntax Coloring of Source Code =ˆà 2 ˆà Trac supports language-specific syntax highlighting of source code in [wiki:WikiFormatting wiki formatted] text and the [wiki:TracBrowser repository browser].ˆàˆà 2 Trac supports language-specific syntax highlighting of source code within wiki formatted text in [WikiProcessors#CodeHighlightingSupport wiki processors] blocks and in the [TracBrowser repository browser].ˆà 3 3 ˆà 4 4 To do this, Trac uses external libraries with support for a great number of programming languages.ˆà òÀæ òÀæ ˆà 6 6 Currently Trac supports syntax coloring using one or more of the following packages:ˆà 7 7 ˆà 8 ˆà * [http:// www.codento.com/people/mtr/genscript/ GNU Enscript]ˆà9 ˆà * [http:// silvercity.sourceforge.net/ SilverCity]ˆà10 ˆà * [http:// pygments.pocoo.org/ Pygments] (but needs a plugin for 0.10, see [#AboutPygments below])ˆàˆà 8 * [http://pygments.pocoo.org/ Pygments], by far the preferred system, as it covers a wide range of programming languages and other structured texts and is actively supportedˆà ˆà 9 * [http://www.codento.com/people/mtr/genscript/ GNU Enscript], commonly available on Unix but somewhat unsupported on Windowsˆà ˆà 10 * [http://silvercity.sourceforge.net/ SilverCity], legacy system, some versions can be [http://trac.edgewall.org/wiki/TracFaq#why-is-my-css-code-not-being-highlighted-even-though-i-have-silvercity-installed problematic]ˆà 11 11 ˆà 12 ˆà To activate syntax coloring, simply install either one (or more) of these packages. No additional configuration is required, however to modify the colors, have a look at `trac/htdocs/css/code.css`.ˆà13 12 ˆà 14 ˆà If you don't know why trac isnt detecting an installed library, try turning on Trac logging. It actually appears that Trac is broken with !SilverCity 0.9.6. Either use the current 0.9.7 or the older 0.9.5 http://trac.edgewall.org/wiki/TracFaq#why-is-my-css-code-not-being-highlighted-even-though-i-have-silvercity-installedˆà ˆà 13 To activate syntax coloring, simply install either one (or more) of these packages (see [#ExtraSoftware] section below).ˆà ˆà 14 If none of these packages is available, Trac will display the data as plain text. ˆà 15 15 ˆà 16 ˆà When in use, Trac will automatically prioritize !SilverCity highlighting over Enscript if possible, (see note below).ˆà17 ˆà ˆà18 ˆà If neither package is available, Trac will display the data as plain text.ˆà19 ˆà ˆà20 ˆà '''Note:''' Enscript supports a greater number of languages, however !SilverCity is generally faster since it is a library and isn't executed in an external process.ˆà21 ˆà ˆà22 ˆà === About !SilverCity ===ˆà23 ˆà !SilverCity uses the lexer from [http://www.scintilla.org/ Scintilla]. Scintilla supports more languages than !SilverCity implements. If you want to add a language to !SilverCity supported by Scintilla, it's not very difficult. See [http://trac.edgewall.org/wiki/SilverCityAddLanguage SilverCityAddLanguage] for some information how.ˆà24 16 ˆà 25 17 === About Pygments ===ˆà 26 18 ˆà 27 ˆà Starting with trac 0.11 [http://pygments.org/ pygments] will be the new default highlighter. It's a highlighting library implemented in pure python, very fast, easy to extend and [http://pygments.org/docs/ well documented]. While it does not support as many languages as Enscript or Scintilla the overall output quality is much better.ˆàˆà 19 Starting with trac 0.11 [http://pygments.org/ pygments] will be the new default highlighter. It's a highlighting library implemented in pure python, very fast, easy to extend and [http://pygments.org/docs/ well documented].ˆà 28 20 ˆà 29 ˆà To use pygments in trac 0.11 you just have to install pygments 0.6 or higher. If you want to use it in trac 0.10 too you have to install the [th:TracPygmentsPlugin TracPygmentsPlugin] from trac hacks. If you encounter any bugs, please file tickets regarding Pygments at [http://dev.pocoo.org/projects/pygments/ the Pygments Trac site].ˆà 30 ˆà ˆà 31 ˆà The Pygments default style can specified in the [TracIni#mimeviewer-section mime-viewer] section of trac.ini. The default style can be over-ridden by setting a Style preference on the [/prefs/pygments preferences page]. ˆà ˆà 21 The Pygments default style can specified in the [TracIni#mimeviewer-section mime-viewer] section of trac.ini. The default style can be overridden by setting a Style preference on the [/prefs/pygments preferences page]. ˆà 32 22 ˆà 33 23 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 [http://pygments.org/docs/lexers/ supported lexers] on the pygments webpage.ˆà òÀæ òÀæ ˆà 36 26 == Syntax Coloring Support ==ˆà 37 27 ˆà 38 ˆà || || !SilverCity || Enscript || Pygments ||ˆà 39 ˆà || Ada || || X || ||ˆà 40 ˆà || Asm || || X || ||ˆà 41 ˆà || Apache Conf (htaccess)) || || || X ||ˆà 42 ˆà || * ASP || X || X || ||ˆà 43 ˆà || * C || X || X || X ||ˆà 44 ˆà || * C# || || X(2) || X ||ˆà 45 ˆà || * C++ || X || X || X ||ˆà 46 ˆà || * Java || X(4)|| X || X ||ˆà 47 ˆà || Awk || || X || ||ˆà 48 ˆà || Boo || || || X ||ˆà 49 ˆà || CSS || X || || X ||ˆà 50 ˆà || Python Doctests || || || X ||ˆà 51 ˆà || Diff || || X || X ||ˆà 52 ˆà || Eiffel || || X || ||ˆà 53 ˆà || Elisp || || X || ||ˆà 54 ˆà || Fortran || || X(3) || X ||ˆà 55 ˆà || Haskell || || X || X ||ˆà 56 ˆà || Genshi || || || X ||ˆà 57 ˆà || HTML || X || X || X ||ˆà 58 ˆà || IDL || || X || ||ˆà 59 ˆà || INI || || || X ||ˆà 60 ˆà || Javascript || X || X || X ||ˆà 61 ˆà || Lua || || || X ||ˆà 62 ˆà || m4 || || X || ||ˆà 63 ˆà || Makefile || || X || X ||ˆà 64 ˆà || Mako || || || X ||ˆà 65 ˆà || Matlab || || X (5) || ||ˆà 66 ˆà || Mygthy || || || X ||ˆà 67 ˆà || Objective-C|| || X ||X ||ˆà 68 ˆà || OCaml || || || X ||ˆà 69 ˆà || Pascal || || X || X ||ˆà 70 ˆà || * Perl || X || X || X ||ˆà 71 ˆà || * PHP || X || || X ||ˆà 72 ˆà || PSP || X || || ||ˆà 73 ˆà || Pyrex || || X || ||ˆà 74 ˆà || * Python || X || X || X ||ˆà 75 ˆà || * Ruby || X || X (1) || X ||ˆà 76 ˆà || Scheme || || X || X ||ˆà 77 ˆà || Shell || || X || X ||ˆà 78 ˆà || Smarty || || || X ||ˆà 79 ˆà || SQL || X || X || X ||ˆà 80 ˆà || Troff || || X || X ||ˆà 81 ˆà || TCL || || X || ||ˆà 82 ˆà || Tex || || X || X ||ˆà 83 ˆà || Verilog || X(4) || X || ||ˆà 84 ˆà || VHDL || || X || ||ˆà 85 ˆà || Visual Basic |||| X || X ||ˆà 86 ˆà || VRML || || X || ||ˆà 87 ˆà || XML || X || || X ||ˆà ˆà 28 === Known MIME Typesˆà 88 29 ˆà 89 ˆà ''(*) Supported as inline code blocks in [wiki:WikiFormatting Wiki text] using WikiProcessors.''ˆà ˆà 30 [[KnownMimeTypes]]ˆà 90 31 ˆà 91 ˆà ''(1) Ruby highlighting is not included in the Enscript distribution. Highlighting rules for Ruby can be obtained from: http://neugierig.org/software/ruby/ˆà ˆà 32 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.ˆà 92 33 ˆà 93 ˆà ''(2) C# highlighting is not included in the Enscript distribution. Highlighting rules for C# can be obtained from: http://wiki.hasno.info/index.php/Csharp.stˆà ˆà 34 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.ˆà 94 35 ˆà 95 ˆà ''(3) Fortran: as packaged, Enscript only supports the fixed source form. Highlighting rules for Fortran 90x/2003 can be obtained from: http://wiki.hasno.info/index.php/F90.stˆà ˆà 36 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.ˆà 96 37 ˆà 97 ˆà ''(4) since Silvercity 0.9.7 released on 2006-11-23ˆà ˆà 38 If mimetype such as 'svn:mime-type' is set to 'text/plain', there is no coloring even if file is known type like 'java'.ˆà 98 39 ˆà 99 ˆà ''(5) By default `.m` files are considered Objective-C files. In order to treat `.m` files as MATLAB files, add "text/x-matlab:m" to the "mime_map" setting in the [wiki:TracIni#mimeviewer-section "[mimeviewer] section of trac.ini"].ˆà ˆà 40 === List of Languages Supported, by Highlighter #language-supportedˆà ˆà 41 ˆà ˆà 42 This list is only indicative.ˆà ˆà 43 ˆà ˆà 44 || ||= !SilverCity =||= Enscript =||= Pygments =||ˆà ˆà 45 || Ada || || òÜÓ || ||ˆà ˆà 46 || Asm || || òÜÓ || ||ˆà ˆà 47 || Apache Conf || || || òÜÓ ||ˆà ˆà 48 || ASP || òÜÓ || òÜÓ || ||ˆà ˆà 49 || C || òÜÓ || òÜÓ || òÜÓ ||ˆà ˆà 50 || C# || || òÜÓ ^[#a1 (1)]^ || òÜÓ ||ˆà ˆà 51 || C++ || òÜÓ || òÜÓ || òÜÓ ||ˆà ˆà 52 || CMake || ? || ? || òÜÓ ||ˆà ˆà 53 || Java || òÜÓ ^[#a2 (2)]^ || òÜÓ || òÜÓ ||ˆà ˆà 54 || Awk || || òÜÓ || ||ˆà ˆà 55 || Boo || || || òÜÓ ||ˆà ˆà 56 || CSS || òÜÓ || || òÜÓ ||ˆà ˆà 57 || Python Doctests || || || òÜÓ ||ˆà ˆà 58 || Diff || || òÜÓ || òÜÓ ||ˆà ˆà 59 || Eiffel || || òÜÓ || ||ˆà ˆà 60 || Elisp || || òÜÓ || ||ˆà ˆà 61 || Fortran || || òÜÓ ^[#a1 (1)]^ || òÜÓ ||ˆà ˆà 62 || Haskell || || òÜÓ || òÜÓ ||ˆà ˆà 63 || Genshi || || || òÜÓ ||ˆà ˆà 64 || HTML || òÜÓ || òÜÓ || òÜÓ ||ˆà ˆà 65 || IDL || || òÜÓ || ||ˆà ˆà 66 || INI || || || òÜÓ ||ˆà ˆà 67 || Javascript || òÜÓ || òÜÓ || òÜÓ ||ˆà ˆà 68 || Lua || || || òÜÓ ||ˆà ˆà 69 || m4 || || òÜÓ || ||ˆà ˆà 70 || Makefile || || òÜÓ || òÜÓ ||ˆà ˆà 71 || Mako || || || òÜÓ ||ˆà ˆà 72 || Matlab ^[#a3 (3)]^ || || òÜÓ || òÜÓ ||ˆà ˆà 73 || Mygthy || || || òÜÓ ||ˆà ˆà 74 || Objective-C || || òÜÓ || òÜÓ ||ˆà ˆà 75 || OCaml || || || òÜÓ ||ˆà ˆà 76 || Pascal || || òÜÓ || òÜÓ ||ˆà ˆà 77 || Perl || òÜÓ || òÜÓ || òÜÓ ||ˆà ˆà 78 || PHP || òÜÓ || || òÜÓ ||ˆà ˆà 79 || PSP || òÜÓ || || ||ˆà ˆà 80 || Pyrex || || òÜÓ || ||ˆà ˆà 81 || Python || òÜÓ || òÜÓ || òÜÓ ||ˆà ˆà 82 || Ruby || òÜÓ || òÜÓ ^[#a1 (1)]^ || òÜÓ ||ˆà ˆà 83 || Scheme || || òÜÓ || òÜÓ ||ˆà ˆà 84 || Shell || || òÜÓ || òÜÓ ||ˆà ˆà 85 || Smarty || || || òÜÓ ||ˆà ˆà 86 || SQL || òÜÓ || òÜÓ || òÜÓ ||ˆà ˆà 87 || Troff || || òÜÓ || òÜÓ ||ˆà ˆà 88 || TCL || || òÜÓ || ||ˆà ˆà 89 || Tex || || òÜÓ || òÜÓ ||ˆà ˆà 90 || Verilog || òÜÓ ^[#a2 (2)]^ || òÜÓ || ||ˆà ˆà 91 || VHDL || || òÜÓ || ||ˆà ˆà 92 || Visual Basic || || òÜÓ || òÜÓ ||ˆà ˆà 93 || VRML || || òÜÓ || ||ˆà ˆà 94 || XML || òÜÓ || || òÜÓ ||ˆà ˆà 95 ˆà ˆà 96 ˆà ˆà 97 ˆà ˆà 98 ''[=#a1 (1)] Not included in the Enscript distribution. Additional highlighting rules can be obtained forˆà ˆà 99 [http://neugierig.org/software/ruby/ Ruby],ˆà ˆà 100 [http://wiki.hasno.info/index.php/Csharp.st C#],ˆà ˆà 101 [http://wiki.hasno.info/index.php/F90.st Fortran 90x/2003]ˆà ˆà 102 ˆà ˆà 103 ''[=#a2 (2)] since Silvercity 0.9.7 released on 2006-11-23ˆà ˆà 104 ˆà ˆà 105 ''[=#a3 (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 [wiki:TracIni#mimeviewer-section "[mimeviewer] section of trac.ini"].ˆà 100 106 ˆà 101 107 == Extra Software ==ˆà 102 ˆà * GNU Enscript --http://directory.fsf.org/GNU/enscript.htmlˆà103 ˆà * GNU Enscript for Windows --http://gnuwin32.sourceforge.net/packages/enscript.htmˆà104 ˆà * !SilverCity --http://silvercity.sf.net/ˆà105 ˆà * Pygments -- http://pygments.org/ˆàˆà 108 * GNU Enscript òÀÔ http://directory.fsf.org/GNU/enscript.htmlˆà ˆà 109 * GNU Enscript for Windows òÀÔ http://gnuwin32.sourceforge.net/packages/enscript.htmˆà ˆà 110 * !SilverCity òÀÔ http://silvercity.sf.net/ˆà ˆà 111 * **Pygments òÀÔ http://pygments.org/**ˆà 106 112 ˆà 107 113 ----ˆà 108 114 See also: WikiProcessors, WikiFormatting, TracWiki, TracBrowserˆà 109 ˆà ˆà