Changes between Version 1 and Version 2 of 1.1/TracSyntaxColoring
- Timestamp:
- Oct 27, 2014, 6:09:24 PM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
1.1/TracSyntaxColoring
v1 v2 1 ** Note: this page documents the 1.0 version of Trac, see [[0.12/TracSyntaxColoring]] if you need the previous version ** 2 = Syntax Coloring of Source Code = 1 ** Note: this page documents the 1.1 version of Trac, see [[TracSyntaxColoring]] if you need the current version ** 2 3 = Syntax Coloring of Source Code 3 4 [[TranslatedPages]] 4 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]. 5 6 To do this, Trac uses external libraries with support for a great number of programming languages. 7 8 Currently Trac supports syntax coloring using one or more of the following packages: 9 10 * [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 11 * [http://www.codento.com/people/mtr/genscript/ GNU Enscript], commonly available on Unix but somewhat unsupported on Windows //(use is deprecated)// 12 * [http://silvercity.sourceforge.net/ SilverCity], legacy system, some versions can be problematic //(use is deprecated)// 5 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]. Syntax coloring is provided using [http://pygments.pocoo.org/ 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. 13 6 14 7 15 To activate syntax coloring, simply install either one (or more) of these packages (see [#ExtraSoftware] section below). 16 If none of these packages is available, Trac will display the data as plain text. 8 === About Pygments 9 10 [http://pygments.org/ Pygments] is a highlighting library implemented in pure python, very fast, easy to extend and [http://pygments.org/docs/ well documented]. 11 12 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]. 17 13 18 14 19 == = About Pygments ===15 == Syntax Coloring Support 20 16 21 Since Trac 0.11 [http://pygments.org/ pygments] is 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]. 17 === Supported languages 22 18 23 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].19 The list of currently supported languages can be found on the [http://pygments.org/languages/ 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 [http://pygments.org/docs/lexers/ supported lexers] provides additional information about the default mime type to keyword mappings. 24 20 25 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.21 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 [wiki:TracIni#mimeviewer-section "[mimeviewer] section of trac.ini"]. 26 22 23 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`. 27 24 28 == Syntax Coloring Support ==25 === Direct Rendering 29 26 30 === Known MIME Types 31 32 [[KnownMimeTypes]] 33 34 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. 27 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. 35 28 36 29 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. … … 38 31 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. 39 32 40 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'. 33 === Known MIME types 41 34 42 === List of Languages Supported, by Highlighter #language-supported 43 44 This list is only indicative. 45 46 || ||= !SilverCity =||= Enscript =||= Pygments =|| 47 || Ada || || ✓ || || 48 || Asm || || ✓ || || 49 || Apache Conf || || || ✓ || 50 || ASP || ✓ || ✓ || || 51 || C || ✓ || ✓ || ✓ || 52 || C# || || ✓ ^[#a1 (1)]^ || ✓ || 53 || C++ || ✓ || ✓ || ✓ || 54 || CMake || ? || ? || ✓ || 55 || Java || ✓ ^[#a2 (2)]^ || ✓ || ✓ || 56 || Awk || || ✓ || || 57 || Boo || || || ✓ || 58 || CSS || ✓ || || ✓ || 59 || Python Doctests || || || ✓ || 60 || Diff || || ✓ || ✓ || 61 || Eiffel || || ✓ || || 62 || Elisp || || ✓ || || 63 || Fortran || || ✓ ^[#a1 (1)]^ || ✓ || 64 || Haskell || || ✓ || ✓ || 65 || Genshi || || || ✓ || 66 || HTML || ✓ || ✓ || ✓ || 67 || IDL || || ✓ || || 68 || INI || || || ✓ || 69 || Javascript || ✓ || ✓ || ✓ || 70 || Lua || || || ✓ || 71 || m4 || || ✓ || || 72 || Makefile || || ✓ || ✓ || 73 || Mako || || || ✓ || 74 || Matlab ^[#a3 (3)]^ || || ✓ || ✓ || 75 || Mygthy || || || ✓ || 76 || Objective-C || || ✓ || ✓ || 77 || OCaml || || || ✓ || 78 || Pascal || || ✓ || ✓ || 79 || Perl || ✓ || ✓ || ✓ || 80 || PHP || ✓ || || ✓ || 81 || PSP || ✓ || || || 82 || Pyrex || || ✓ || || 83 || Python || ✓ || ✓ || ✓ || 84 || Ruby || ✓ || ✓ ^[#a1 (1)]^ || ✓ || 85 || Scheme || || ✓ || ✓ || 86 || Shell || || ✓ || ✓ || 87 || Smarty || || || ✓ || 88 || SQL || ✓ || ✓ || ✓ || 89 || Troff || || ✓ || ✓ || 90 || TCL || || ✓ || || 91 || Tex || || ✓ || ✓ || 92 || Verilog || ✓ ^[#a2 (2)]^ || ✓ || || 93 || VHDL || || ✓ || || 94 || Visual Basic || || ✓ || ✓ || 95 || VRML || || ✓ || || 96 || XML || ✓ || || ✓ || 97 98 99 100 ''[=#a1 (1)] Not included in the Enscript distribution. Additional highlighting rules can be obtained for 101 [http://neugierig.org/software/ruby/ Ruby], 102 [http://wiki.hasno.info/index.php/Csharp.st C#], 103 [http://wiki.hasno.info/index.php/F90.st Fortran 90x/2003] 104 105 ''[=#a2 (2)] since Silvercity 0.9.7 released on 2006-11-23 106 107 ''[=#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"]. 108 109 == Extra Software == 110 * GNU Enscript — http://directory.fsf.org/GNU/enscript.html 111 * GNU Enscript for Windows — http://gnuwin32.sourceforge.net/packages/enscript.htm 112 * !SilverCity — http://silvercity.sf.net/ 113 * **Pygments — http://pygments.org/** 35 [[KnownMimeTypes]] 114 36 115 37 ----