Changes between Version 2 and Version 3 of WikiProcessors


Ignore:
Timestamp:
11/14/18 14:30:10 (5 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WikiProcessors

    v2 v3  
    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 
     1= Wiki Processors
     2
     3Processors are WikiMacros that provide alternative markup formats for the [TracWiki Wiki engine]. Processors can be thought of as ''macro functions to process user-edited text''.
     4
     5Wiki processors can be used in any Wiki text throughout Trac, such as:
     6 - [#CodeHighlightingSupport syntax highlighting] or for rendering text verbatim
     7 - rendering [#HTMLrelated Wiki markup inside a context] such as <div> or <span> blocks or within <td> or <th> table cells
     8 - using an alternative markup syntax, like [WikiHtml raw HTML] and [WikiRestructuredText Restructured Text] or [http://www.textism.com/tools/textile/ textile]
     9
     10== Using Processors
     11
     12To use a processor on a block of text, first delimit the lines using a Wiki ''code block'':
     13{{{
     14{{{
     15The lines
     16that should be processed...
     17}}}
     18}}}
     19
     20Immediately after the `{{{` or on the line just below, add `#!` followed by the ''processor name'':
     21
     22{{{
     23{{{
     24#!processorname
     25The lines
     26that should be processed...
     27}}}
     28}}}
     29
     30This is the "shebang" notation, familiar to most UNIX users.
     31
     32Besides their content, some Wiki processors can also accept ''parameters'', which are then given as `key=value` pairs after the processor name and on the same line. If `value` has to contain space, as it's often the case for the style parameter, a quoted string can be used (`key="value with space"`).
     33
     34As some processors are meant to process Wiki markup, it's quite possible to ''nest'' processor blocks.
     35You may want to indent the content of nested blocks for increased clarity, this extra indentation will be ignored when processing the content.
     36
     37== Examples
     38
     39||= Wiki Markup =||= Display =||
     40{{{#!td colspan=2 align=center style="border: none"
     41
     42                '''Example 1''': Inserting raw HTML
     43}}}
     44|-----------------------------------------------------------------
     45{{{#!td style="border: none"
     46{{{
    1447{{{
    1548#!html
    16 <pre class="wiki">{{{
     49<h1 style="color: grey">This is raw HTML</h1>
     50}}}
     51}}}
     52}}}
     53{{{#!td valign=top style="border: none; padding-left: 2em"
     54{{{
    1755#!html
    18 &lt;h1 style="color: orange"&gt;This is raw HTML&lt;/h1&gt;
    19 }}}</pre>
    20 }}}
    21 
    22 '''Results in:'''
    23 {{{
    24 #!html
    25 <h1 style="color: orange">This is raw HTML</h1>
    26 }}}
    27 
    28 Note that since 0.11, such blocks of HTML have to be self-contained, i.e. you can't start an HTML element in one block and close it later in a second block. Use div or span processors for achieving similar effect (see WikiHtml).
    29 
    30 ----
    31 
    32 '''Example 2''' (''inserting Restructured Text in wiki text''):
    33 
    34 {{{
    35 #!html
    36 <pre class="wiki">{{{
    37 #!rst
    38 A header
    39 --------
    40 This is some **text** with a footnote [*]_.
    41 
    42 .. [*] This is the footnote.
    43 }}}</pre>
    44 }}}
    45 
    46 '''Results in:'''
    47 {{{
    48 #!rst
    49 A header
    50 --------
    51 This is some **text** with a footnote [*]_.
    52 
    53 .. [*] This is the footnote.
    54 }}}
    55 ----
    56 '''Example 3''' (''inserting a block of C source code in wiki text''):
    57 
    58 {{{
    59 #!html
    60 <pre class="wiki">{{{
    61 #!c
    62 int main(int argc, char *argv[])
    63 {
    64   printf("Hello World\n");
    65   return 0;
    66 }
    67 }}}</pre>
    68 }}}
    69 
    70 '''Results in:'''
    71 {{{
    72 #!c
    73 int main(int argc, char *argv[])
    74 {
    75   printf("Hello World\n");
    76   return 0;
    77 }
    78 }}}
    79 
    80 ----
    81 
    82 == Available Processors ==
     56<h1 style="color: grey">This is raw HTML</h1>
     57}}}
     58}}}
     59|-----------------------------------------------------------------
     60{{{#!td colspan=2 align=center style="border: none"
     61
     62     '''Example 2''': Highlighted Python code in a <div> block with custom style
     63}}}
     64|-----------------------------------------------------------------
     65{{{#!td style="border: none"
     66  {{{
     67  {{{#!div style="background: #ffd; border: 3px ridge"
     68
     69  This is an example of embedded "code" block:
     70
     71    {{{
     72    #!python
     73    def hello():
     74        return "world"
     75    }}}
     76
     77  }}}
     78  }}}
     79}}}
     80{{{#!td valign=top style="border: none; padding: 1em"
     81  {{{#!div style="background: #ffd; border: 3px ridge"
     82
     83  This is an example of embedded "code" block:
     84
     85    {{{
     86    #!python
     87    def hello():
     88        return "world"
     89    }}}
     90
     91  }}}
     92}}}
     93|-----------------------------------------------------------------
     94{{{#!td colspan=2 align=center style="border: none"
     95
     96     '''Example 3''': Searching tickets from a wiki page, by keywords.
     97}}}
     98|-----------------------------------------------------------------
     99{{{#!td style="border: none"
     100  {{{
     101  {{{
     102  #!html
     103  <form action="/query" method="get"><div>
     104  <input type="text" name="keywords" value="~" size="30"/>
     105  <input type="submit" value="Search by Keywords"/>
     106  <!-- To control what fields show up use hidden fields
     107  <input type="hidden" name="col" value="id"/>
     108  <input type="hidden" name="col" value="summary"/>
     109  <input type="hidden" name="col" value="status"/>
     110  <input type="hidden" name="col" value="milestone"/>
     111  <input type="hidden" name="col" value="version"/>
     112  <input type="hidden" name="col" value="owner"/>
     113  <input type="hidden" name="col" value="priority"/>
     114  <input type="hidden" name="col" value="component"/>
     115  -->
     116  </div></form>
     117  }}}
     118  }}}
     119}}}
     120{{{#!td valign=top style="border: none; padding: 1em"
     121  {{{
     122  #!html
     123  <form action="/query" method="get"><div>
     124  <input type="text" name="keywords" value="~" size="30"/>
     125  <input type="submit" value="Search by Keywords"/>
     126  <!-- To control what fields show up use hidden fields
     127  <input type="hidden" name="col" value="id"/>
     128  <input type="hidden" name="col" value="summary"/>
     129  <input type="hidden" name="col" value="status"/>
     130  <input type="hidden" name="col" value="milestone"/>
     131  <input type="hidden" name="col" value="version"/>
     132  <input type="hidden" name="col" value="owner"/>
     133  <input type="hidden" name="col" value="priority"/>
     134  <input type="hidden" name="col" value="component"/>
     135  -->
     136  </div></form>
     137  }}}
     138}}}
     139
     140== Available Processors
     141
    83142The following processors are included in the Trac distribution:
    84  * '''html''' -- Insert custom HTML in a wiki page. See WikiHtml.
    85  * '''div''' -- Wrap an arbitrary Wiki content in a <div> element (''since 0.11''). See WikiHtml.
    86  * '''span''' -- Wrap an arbitrary Wiki content in a <span> element (''since 0.11''). See also WikiHtml.
    87  * '''rst''' -- Trac support for Restructured Text. See WikiRestructuredText.
    88  * '''textile''' -- Supported if [http://cheeseshop.python.org/pypi/textile Textile] is installed. See [http://www.textism.com/tools/textile/ a Textile reference].
    89  * '''comment''' -- Do not process the text in this section (i.e. contents exist only in the plain text - not in the rendered page).
    90  * '''diff''' -- Pretty print patches and diffs.
    91 
    92 === Code Highlighting Support ===
    93 Trac includes processors to provide inline [wiki:TracSyntaxColoring syntax highlighting] for the following languages:
    94  * '''c''' -- C
    95  * '''cpp''' -- C++
    96  * '''csharp''' --- C# (''use #!text/x-csharp'')
    97  * '''python''' -- Python
    98  * '''perl''' -- Perl
    99  * '''ruby''' -- Ruby
    100  * '''php''' -- PHP
    101  * '''asp''' -- ASP
    102  * '''java''' -- Java
    103  * '''js''' -- Javascript
    104  * '''sql''' -- SQL
    105  * '''xml''' -- XML
    106  * '''sh''' -- Bourne/Bash shell
    107 
    108 '''Note:''' ''Trac relies on external software packages for syntax coloring. See TracSyntaxColoring for more info.''
    109 
    110 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:
    111 {{{
    112 {{{
    113 #!text/html
     143
     144|| '''`#!default`''' || Present the text verbatim in a preformatted text block. This is the same as specifying ''no'' processor name (and no `#!`). ||
     145|| '''`#!comment`''' || Do not process the text in this section, i.e. contents exist only in the plain text - not in the rendered page. ||
     146|| '''`#!rtl`''' || Introduce a Right-To-Left block with appropriate CSS direction and styling. ''(since 0.12.2)'' ||
     147|||| ||
     148||||= '''[=#HTMLrelated HTML related]''' =||
     149|| '''`#!html`''' || Insert custom HTML in a wiki page. ||
     150|| '''`#!htmlcomment`''' || Insert an HTML comment in a wiki page. (''since 0.12'') ||
     151|| || Note that `#!html` blocks have to be ''self-contained'', i.e. you can't start an HTML element in one block and close it later in a second block. Use the following processors for achieving a similar effect.  ||
     152|| '''`#!div`''' || Wrap wiki content inside a <div> element. ||
     153|| '''`#!span`''' || Wrap wiki content inside a <span> element. ||
     154|| '''`#!td`''' || Wrap wiki content inside a <td> element. (''since 0.12'') ||
     155|| '''`#!th`''' || Wrap wiki content inside a <th> element. (''since 0.12'') ||
     156|| '''`#!tr`''' || Can optionally be used for wrapping `#!td` and `#!th` blocks, either for specifying row attributes or better visual grouping. (''since 0.12'') ||
     157|| '''`#!table`''' || Can optionally be used for wrapping `#!tr`, `#!td` and `#!th` blocks, for specifying table attributes. One current limitation however is that tables cannot be nested. (''since 0.12'') ||
     158|| || See WikiHtml for example usage and more details about these processors. ||
     159|||| ||
     160||||= '''Other Markups''' =||
     161|| '''`#!rst`''' || Trac support for Restructured Text. See WikiRestructuredText. ||
     162|| '''`#!textile`''' || Supported if [http://cheeseshop.python.org/pypi/textile Textile] is installed. See [http://www.textism.com/tools/textile/ a Textile reference]. ||
     163|||| ||
     164||||= '''[=#CodeHighlightingSupport Code Highlighting Support]''' =||
     165|| '''`#!c`''' [[BR]] '''`#!cpp`''' (C++) [[BR]] '''`#!python`''' [[BR]] '''`#!perl`''' [[BR]] '''`#!ruby`''' [[BR]] '''`#!php`''' [[BR]] '''`#!asp`''' [[BR]] '''`#!java`''' [[BR]] '''`#!js`''' (Javascript) [[BR]] '''`#!sql`''' [[BR]] '''`#!xml`''' (XML or HTML) [[BR]] '''`#!sh`''' (!Bourne/Bash shell) [[BR]] || Trac includes processors to provide inline syntax highlighting for source code in various languages. [[BR]] [[BR]] Trac relies on [http://pygments.org Pygments] for syntax coloring. [[BR]] [[BR]] See TracSyntaxColoring for information about which languages are supported and how to enable support for more languages. ||
     166|||| ||
     167
     168Since 1.1.2 the default, coding highlighting and MIME-type processors support the argument `lineno` for adding line numbering to the code block. When a value is specified, as in `lineno=3`, the numbering will start at the specified value. When used in combination with the `lineno` argument, the `marks` argument is also supported for highlighting lines. A single line number, set of line numbers and range of line numbers are allowed. For example, `marks=3`, `marks=3-6`, `marks=3,5,7` and `marks=3-5,7` are all allowed. The specified values are relative to the numbered lines, so if `lineno=2` is specified to start the line numbering at 2, `marks=2` will result in the first line being highlighted.
     169
     170Using the MIME type as processor, it is possible to syntax-highlight the same languages that are supported when browsing source code.
     171
     172||||= '''MIME Type Processors''' =||
     173{{{#!tr
     174{{{#!td
     175Some examples:
     176 {{{
     177{{{#!text/html
    114178<h1>text</h1>
    115179}}}
    116 }}}
    117 
     180 }}}
     181}}}
     182{{{#!td
    118183The result will be syntax highlighted HTML code:
    119 {{{
    120 #!text/html
     184 {{{#!text/html
    121185<h1>text</h1>
    122 }}}
    123 
    124 The same is valid for all other mime types supported.
    125 
    126 
    127 For more processor macros developed and/or contributed by users, visit:
    128  * [trac:ProcessorBazaar]
    129  * [trac:MacroBazaar]
    130  * [th:WikiStart Trac Hacks] community site
    131 
    132 
    133 == Advanced Topics: Developing Processor Macros ==
    134 Developing processors is no different from Wiki macros. In fact they work the same way, only the usage syntax differs. See WikiMacros for more information.
    135 
     186 }}}
     187
     188The same is valid for all other [TracSyntaxColoring#SyntaxColoringSupport mime types supported].
     189}}}
     190}}}
     191{{{#!td
     192 {{{
     193{{{#!diff
     194--- Version 55
     195+++ Version 56
     196@@ -115,8 +115,9 @@
     197     name='TracHelloWorld', version='1.0',
     198     packages=find_packages(exclude=['*.tests*']),
     199-    entry_points = """
     200-        [trac.plugins]
     201-        helloworld = myplugs.helloworld
     202-    """,
     203+    entry_points = {
     204+        'trac.plugins': [
     205+            'helloworld = myplugs.helloworld',
     206+        ],
     207+    },
     208 )
     209}}}
     210 }}}
     211}}}
     212{{{#!td
     213'''`#!diff`''' has a particularly nice renderer:
     214 {{{#!diff
     215--- Version 55
     216+++ Version 56
     217@@ -115,8 +115,9 @@
     218     name='TracHelloWorld', version='1.0',
     219     packages=find_packages(exclude=['*.tests*']),
     220-    entry_points = """
     221-        [trac.plugins]
     222-        helloworld = myplugs.helloworld
     223-    """,
     224+    entry_points = {
     225+        'trac.plugins': [
     226+            'helloworld = myplugs.helloworld',
     227+        ],
     228+    },
     229 )
     230 }}}
     231}}}
     232
     233Line numbers can be added to code blocks and lines can be highlighted //(since 1.1.2)//.
     234{{{
     235{{{#!python lineno=3 marks=3,9-10,16
     236def expand_markup(stream, ctxt=None):
     237    """A Genshi stream filter for expanding `genshi.Markup` events.
     238
     239    Note: Expansion may not be possible if the fragment is badly
     240    formed, or partial.
     241    """
     242    for event in stream:
     243        if isinstance(event[1], Markup):
     244            try:
     245                for subevent in HTML(event[1]):
     246                    yield subevent
     247            except ParseError:
     248                yield event
     249        else:
     250            yield event
     251}}}
     252}}}
     253{{{#!python lineno=3 marks=3,9-10,16
     254def expand_markup(stream, ctxt=None):
     255    """A Genshi stream filter for expanding `genshi.Markup` events.
     256
     257    Note: Expansion may not be possible if the fragment is badly
     258    formed, or partial.
     259    """
     260    for event in stream:
     261        if isinstance(event[1], Markup):
     262            try:
     263                for subevent in HTML(event[1]):
     264                    yield subevent
     265            except ParseError:
     266                yield event
     267        else:
     268            yield event
     269}}}
     270
     271For more processor macros developed and/or contributed by users, visit the [https://trac-hacks.org Trac Hacks] community site.
     272
     273Processors are implemented using the same interfaces as Wiki macros, only the usage syntax differs. To develop a processor, see WikiMacros#DevelopingCustomMacros.
    136274
    137275----