| 1 | = Wiki Processors = |
---|
| 2 | |
---|
| 3 | Processors are WikiMacros designed to provide alternative markup formats for the [TracWiki Wiki engine]. Processors can be thought of as ''macro functions to process user-edited text''. |
---|
| 4 | |
---|
| 5 | The Wiki engine uses processors to allow using [wiki:WikiRestructuredText Restructured Text], [wiki:WikiHtml raw HTML] and [http://www.textism.com/tools/textile/ textile] in any Wiki text throughout Trac. |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | == Using Processors == |
---|
| 9 | |
---|
| 10 | To use a processor on a block of text, use a Wiki code block, selecting a processor by name using ''shebang notation'' (#!), familiar to most UNIX users from scripts. |
---|
| 11 | |
---|
| 12 | '''Example 1''' (''inserting raw HTML in a wiki text''): |
---|
| 13 | |
---|
| 14 | {{{ |
---|
| 15 | #!html |
---|
| 16 | <pre class="wiki">{{{ |
---|
| 17 | #!html |
---|
| 18 | <h1 style="color: orange">This is raw HTML</h1> |
---|
| 19 | }}}</pre> |
---|
| 20 | }}} |
---|
| 21 | |
---|
| 22 | '''Results in:''' |
---|
| 23 | {{{ |
---|
| 24 | #!html |
---|
| 25 | <h1 style="color: orange">This is raw HTML</h1> |
---|
| 26 | }}} |
---|
| 27 | |
---|
| 28 | ---- |
---|
| 29 | |
---|
| 30 | '''Example 2''' (''inserting Restructured Text in wiki text''): |
---|
| 31 | |
---|
| 32 | {{{ |
---|
| 33 | #!html |
---|
| 34 | <pre class="wiki">{{{ |
---|
| 35 | #!rst |
---|
| 36 | A header |
---|
| 37 | -------- |
---|
| 38 | This is some **text** with a footnote [*]_. |
---|
| 39 | |
---|
| 40 | .. [*] This is the footnote. |
---|
| 41 | }}}</pre> |
---|
| 42 | }}} |
---|
| 43 | |
---|
| 44 | '''Results in:''' |
---|
| 45 | {{{ |
---|
| 46 | #!rst |
---|
| 47 | A header |
---|
| 48 | -------- |
---|
| 49 | This is some **text** with a footnote [*]_. |
---|
| 50 | |
---|
| 51 | .. [*] This is the footnote. |
---|
| 52 | }}} |
---|
| 53 | ---- |
---|
| 54 | '''Example 3''' (''inserting a block of C source code in wiki text''): |
---|
| 55 | |
---|
| 56 | {{{ |
---|
| 57 | #!html |
---|
| 58 | <pre class="wiki">{{{ |
---|
| 59 | #!c |
---|
| 60 | int main(int argc, char *argv[]) |
---|
| 61 | { |
---|
| 62 | printf("Hello World |
---|
| 63 | "); |
---|
| 64 | return 0; |
---|
| 65 | } |
---|
| 66 | }}}</pre> |
---|
| 67 | }}} |
---|
| 68 | |
---|
| 69 | '''Results in:''' |
---|
| 70 | {{{ |
---|
| 71 | #!c |
---|
| 72 | int main(int argc, char *argv[]) |
---|
| 73 | { |
---|
| 74 | printf("Hello World |
---|
| 75 | "); |
---|
| 76 | return 0; |
---|
| 77 | } |
---|
| 78 | }}} |
---|
| 79 | |
---|
| 80 | ---- |
---|
| 81 | |
---|
| 82 | == Available Processors == |
---|
| 83 | The following processors are included in the Trac distribution: |
---|
| 84 | * '''html''' -- Insert custom HTML in a wiki page. See WikiHtml. |
---|
| 85 | * '''rst''' -- Trac support for Restructured Text. See WikiRestructuredText. |
---|
| 86 | * '''textile''' -- Supported if [http://dealmeida.net/projects/textile/ Textile] is installed. See [http://hobix.com/textile/ a Textile reference]. |
---|
| 87 | |
---|
| 88 | Textile link above is rotten. [http://www.textism.com/tools/textile/ this one] works, allows to test example. |
---|
| 89 | |
---|
| 90 | === Code Highlighting Support === |
---|
| 91 | Trac includes processors to provide inline [wiki:TracSyntaxColoring syntax highlighting] for the following languages: |
---|
| 92 | * '''c''' -- C |
---|
| 93 | * '''cpp''' -- C++ |
---|
| 94 | * '''python''' -- Python |
---|
| 95 | * '''perl''' -- Perl |
---|
| 96 | * '''ruby''' -- Ruby |
---|
| 97 | * '''php''' -- PHP |
---|
| 98 | * '''asp''' --- ASP |
---|
| 99 | * '''sql''' -- SQL |
---|
| 100 | * '''xml''' -- XML |
---|
| 101 | '''Note:''' ''Trac relies on external software packages for syntax coloring. See TracSyntaxColoring for more info.'' |
---|
| 102 | |
---|
| 103 | By using the MIME type as processor, it is possible to syntax-highlight the same languages that are supported when browsing source code. For example, you can write: |
---|
| 104 | {{{ |
---|
| 105 | {{{ |
---|
| 106 | #!text/html |
---|
| 107 | <h1>text</h1> |
---|
| 108 | }}} |
---|
| 109 | }}} |
---|
| 110 | |
---|
| 111 | The result will be syntax highlighted HTML code. The same is valid for all other mime types supported. |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | For more processor macros developed and/or contributed by users, visit: |
---|
| 115 | * [http://projects.edgewall.com/trac/wiki/ProcessorBazaar ProcessorBazaar] |
---|
| 116 | * [http://projects.edgewall.com/trac/wiki/MacroBazaar MacroBazaar] |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | == Advanced Topics: Developing Processor Macros == |
---|
| 120 | Developing processors is no different from WikiMacros. In fact they work the same way, only the usage syntax differs. See WikiMacros for more information. |
---|
| 121 | |
---|
| 122 | '''Example:''' (''Restructured Text Processor''): |
---|
| 123 | {{{ |
---|
| 124 | #!python |
---|
| 125 | from docutils.core import publish_string |
---|
| 126 | |
---|
| 127 | def execute(hdf, text, env): |
---|
| 128 | html = publish_string(text, writer_name = 'html') |
---|
| 129 | return html[html.find('<body>')+6:html.find('</body>')].strip() |
---|
| 130 | }}} |
---|
| 131 | |
---|
| 132 | ---- |
---|
| 133 | See also: WikiMacros, WikiHtml, WikiRestructuredText, TracSyntaxColoring, WikiFormatting, TracGuide |