Source

trac-ticketlinks / wiki-default / WikiProcessors

= Wiki Processors =
Processors are WikiMacros designed to provide alternative markup formats for the Trac Wiki engine. Processors can be thought of as ''macro functions to process user-edited text''. 

The wiki engine uses processors to allow using [wiki:WikiRestructuredText Restructured Text] and [wiki:WikiHtml raw HTML] in any wiki text throughout Trac.

== Using Processors ==
To use a processor on a block of text, use a wiki blockquote, selecting a processor by name using 'hashbang notation' (#!), familiar to most UNIX users from scripts.

'''Example 1''' (''inserting raw HTML in a wiki text''):

{{{
#!html
<pre class="wiki">{{{
#!html
&lt;h1 style="color: orange"&gt;This is raw HTML&lt;/h1&gt;
}}}</pre>
}}}

'''Results in:'''
{{{
#!html
<h1 style="color: orange">This is raw HTML</h1>
}}}

----

'''Example 2''' (''inserting Restructured Text in wiki text''):

{{{
#!html
<pre class="wiki">{{{
#!rst
A header
--------
This is some **text** with a footnote [*]_.

.. [*] This is the footnote.
}}}</pre>
}}}

'''Results in:'''
{{{
#!rst
A header
--------
This is some **text** with a footnote [*]_.

.. [*] This is the footnote.
}}}
----
'''Example 3''' (''inserting a block of C source code in wiki text''):

{{{
#!html
<pre class="wiki">{{{
#!c
int main(int argc, char *argv[])
{
  printf("Hello World\n");
  return 0;
}
}}}</pre>
}}}

'''Results in:'''
{{{
#!c
int main(int argc, char *argv[])
{
  printf("Hello World\n");
  return 0;
}
}}}

----



== Available Processors ==
The following processors are included in the Trac distribution:
 * '''html''' -- Insert custom HTML in a wiki page. See WikiHtml.
 * '''rst''' -- Trac support for Restructured Text. See WikiRestructuredText.
 * '''textile''' -- Supported if  [http://dealmeida.net/projects/textile/ Textile] is installed.

=== Source Code Support ===
Trac includes processors to provide inline [wiki:TracSyntaxColoring syntax highlighting] for these languages:
 * '''c''' -- C
 * '''cpp''' -- C++
 * '''python''' -- Python
 * '''perl''' -- Perl
 * '''ruby''' -- Ruby
 * '''php''' -- PHP
 * '''asp''' --- ASP
 * '''sql''' -- SQL
 * '''xml''' -- XML
'''Note:''' ''Trac relies on external software packages for syntax coloring. See TracSyntaxColoring for more info.''

By using the mime-type as processor, it is posible to syntax-highlight the same languages that are supported when browsing source code.

For example, you can write:

{{{
{{{
#!text/html
<h1>text</h1>
}}}
}}}

The result will be syntax highlighted html code. The same is valid for all other mime types supported.



For more processor macros developed and/or contributed by users, visit the macro bazaar: 
 http://projects.edgewall.com/trac/wiki/MacroBazaar

----
== Advanced Topics: Developing Processor Macros ==
Developing processors is no different than WikiMacros. In fact they work the same way, only the usage syntax differs. See WikiMacros for more information.

'''Example:''' (''Restructured Text Processor''):
{{{
from docutils.core import publish_string

def execute(hdf, text, env):
    html = publish_string(text, writer_name = 'html')
    return html[html.find('<body>')+6:html.find('</body>')].strip()
}}}

----
See also : WikiMacros, WikiHtml, WikiRestructuredText, TracSyntaxColoring, WikiFormatting, TracGuide
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.