Edgewall Software

Changes between Initial Version and Version 1 of 1.1/WikiProcessors


Ignore:
Timestamp:
Aug 18, 2014, 7:17:48 AM (10 years ago)
Author:
Ryan J Ollos
Comment:

Copied from WikiProcessors@65.

Legend:

Unmodified
Added
Removed
Modified
  • 1.1/WikiProcessors

    v1 v1  
     1{{{#!box note
     2This page documents the **1.1dev** version of Trac. See [[wiki:/WikiProcessors]] if you need the previous version.
     3}}}
     4= Wiki Processors =
     5
     6Processors 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''.
     7
     8Wiki processors can be used in any Wiki text throughout Trac,
     9for various different purposes, like:
     10 - [#CodeHighlightingSupport syntax highlighting] or for rendering text verbatim,
     11 - rendering [#HTMLrelated Wiki markup inside a context],
     12   like inside <div> blocks or <span> or within <td> or <th> table cells,
     13 - using an alternative markup syntax, like [wiki:WikiHtml raw HTML] and
     14   [wiki:WikiRestructuredText Restructured Text],
     15   or [http://www.textism.com/tools/textile/ textile]
     16
     17
     18== Using Processors ==
     19
     20To use a processor on a block of text, first delimit the lines using
     21a Wiki ''code block'':
     22{{{
     23{{{
     24The lines
     25that should be processed...
     26}}}
     27}}}
     28
     29Immediately after the `{{{` or on the line just below,
     30add `#!` followed by the ''processor name''.
     31
     32{{{
     33{{{
     34#!processorname
     35The lines
     36that should be processed...
     37}}}
     38}}}
     39
     40This is the "shebang" notation, familiar to most UNIX users.
     41
     42Besides their content, some Wiki processors can also accept ''parameters'',
     43which are then given as `key=value` pairs after the processor name,
     44on the same line. If `value` has to contain space, as it's often the case for
     45the style parameter, a quoted string can be used (`key="value with space"`).
     46
     47As some processors are meant to process Wiki markup, it's quite possible to
     48''nest'' processor blocks.
     49You may want to indent the content of nested blocks for increased clarity,
     50this extra indentation will be ignored when processing the content.
     51
     52
     53== Examples ==
     54
     55||= Wiki Markup =||= Display =||
     56{{{#!td colspan=2 align=center style="border: none"
     57
     58                __Example 1__: Inserting raw HTML
     59}}}
     60|-----------------------------------------------------------------
     61{{{#!td style="border: none"
     62{{{
     63{{{
     64#!html
     65<h1 style="color: grey">This is raw HTML</h1>
     66}}}
     67}}}
     68}}}
     69{{{#!td valign=top style="border: none; padding-left: 2em"
     70{{{
     71#!html
     72<h1 style="color: grey">This is raw HTML</h1>
     73}}}
     74}}}
     75|-----------------------------------------------------------------
     76{{{#!td colspan=2 align=center style="border: none"
     77
     78     __Example 2__: Highlighted Python code in a <div> block with custom style
     79}}}
     80|-----------------------------------------------------------------
     81{{{#!td style="border: none"
     82  {{{
     83  {{{#!div style="background: #ffd; border: 3px ridge"
     84
     85  This is an example of embedded "code" block:
     86
     87    {{{
     88    #!python
     89    def hello():
     90        return "world"
     91    }}}
     92
     93  }}}
     94  }}}
     95}}}
     96{{{#!td valign=top style="border: none; padding: 1em"
     97  {{{#!div style="background: #ffd; border: 3px ridge"
     98
     99  This is an example of embedded "code" block:
     100
     101    {{{
     102    #!python
     103    def hello():
     104        return "world"
     105    }}}
     106
     107  }}}
     108}}}
     109|-----------------------------------------------------------------
     110{{{#!td colspan=2 align=center style="border: none"
     111
     112     __Example 3__: Searching tickets from a wiki page, by keywords.
     113}}}
     114|-----------------------------------------------------------------
     115{{{#!td style="border: none"
     116  {{{
     117  {{{
     118  #!html
     119  <form action="/query" method="get"><div>
     120  <input type="text" name="keywords" value="~" size="30"/>
     121  <input type="submit" value="Search by Keywords"/>
     122  <!-- To control what fields show up use hidden fields
     123  <input type="hidden" name="col" value="id"/>
     124  <input type="hidden" name="col" value="summary"/>
     125  <input type="hidden" name="col" value="status"/>
     126  <input type="hidden" name="col" value="milestone"/>
     127  <input type="hidden" name="col" value="version"/>
     128  <input type="hidden" name="col" value="owner"/>
     129  <input type="hidden" name="col" value="priority"/>
     130  <input type="hidden" name="col" value="component"/>
     131  -->
     132  </div></form>
     133  }}}
     134  }}}
     135}}}
     136{{{#!td valign=top style="border: none; padding: 1em"
     137  {{{
     138  #!html
     139  <form action="/query" method="get"><div>
     140  <input type="text" name="keywords" value="~" size="30"/>
     141  <input type="submit" value="Search by Keywords"/>
     142  <!-- To control what fields show up use hidden fields
     143  <input type="hidden" name="col" value="id"/>
     144  <input type="hidden" name="col" value="summary"/>
     145  <input type="hidden" name="col" value="status"/>
     146  <input type="hidden" name="col" value="milestone"/>
     147  <input type="hidden" name="col" value="version"/>
     148  <input type="hidden" name="col" value="owner"/>
     149  <input type="hidden" name="col" value="priority"/>
     150  <input type="hidden" name="col" value="component"/>
     151  -->
     152  </div></form>
     153  }}}
     154}}}
     155== Available Processors ==
     156
     157The following processors are included in the Trac distribution:
     158
     159|| '''`#!default`''' || Present the text verbatim in a preformatted text block. This is the same as specifying ''no'' processor name (and no `#!`) ||
     160|| '''`#!comment`''' || Do not process the text in this section (i.e. contents exist only in the plain text - not in the rendered page). ||
     161|| '''`#!rtl`''' || Introduce a Right-To-Left block with appropriate CSS direction and styling ''(since 0.12.2)'' ||
     162|||| ||
     163||||= '''[=#HTMLrelated HTML related]''' =||
     164|| '''`#!html`''' || Insert custom HTML in a wiki page. ||
     165|| '''`#!htmlcomment`''' || Insert an HTML comment in a wiki page (''since 0.12''). ||
     166|| || 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.  ||
     167|| '''`#!div`''' || Wrap an arbitrary Wiki content inside a <div> element (''since 0.11''). ||
     168|| '''`#!span`''' || Wrap an arbitrary Wiki content inside a <span> element (''since 0.11''). ||
     169|| '''`#!td`''' || Wrap an arbitrary Wiki content inside a <td> element (''since 0.12'') ||
     170|| '''`#!th`''' || Wrap an arbitrary Wiki content inside a <th> element (''since 0.12'') ||
     171|| '''`#!tr`''' || Can optionally be used for wrapping `#!td` and `#!th` blocks, either for specifying row attributes or better visual grouping (''since 0.12'') ||
     172|| '''`#!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'') ||
     173|| || See WikiHtml for example usage and more details about these processors. ||
     174|||| ||
     175||||= '''Other Markups''' =||
     176|| '''`#!rst`''' || Trac support for Restructured Text. See WikiRestructuredText. ||
     177|| '''`#!textile`''' || Supported if [http://cheeseshop.python.org/pypi/textile Textile] is installed. See [http://www.textism.com/tools/textile/ a Textile reference]. ||
     178|||| ||
     179||||= '''[=#CodeHighlightingSupport Code Highlighting Support]''' =||
     180|| '''`#!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]] '''etc.''' [[BR]] || Trac includes processors to provide inline syntax highlighting for source code in various languages. [[BR]] [[BR]] Trac relies on external software packages for syntax coloring, like [http://pygments.org Pygments]. [[BR]] [[BR]] See TracSyntaxColoring for information about which languages are supported and how to enable support for more languages. ||
     181|||| ||
     182
     183Since 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.
     184
     185Using the MIME type as processor, it is possible to syntax-highlight the same languages that are supported when browsing source code.
     186
     187||||= '''MIME Type Processors''' =||
     188{{{#!tr
     189{{{#!td
     190Some examples:
     191 {{{
     192{{{
     193#!text/html
     194<h1>text</h1>
     195}}}
     196 }}}
     197}}}
     198{{{#!td
     199The result will be syntax highlighted HTML code:
     200 {{{
     201#!text/html
     202<h1>text</h1>
     203 }}}
     204
     205The same is valid for all other [TracSyntaxColoring#SyntaxColoringSupport mime types supported].
     206}}}
     207}}}
     208{{{#!td
     209 {{{
     210{{{
     211#!diff
     212--- Version 55
     213+++ Version 56
     214@@ -115,8 +115,9 @@
     215     name='TracHelloWorld', version='1.0',
     216     packages=find_packages(exclude=['*.tests*']),
     217-    entry_points = """
     218-        [trac.plugins]
     219-        helloworld = myplugs.helloworld
     220-    """,
     221+    entry_points = {
     222+        'trac.plugins': [
     223+            'helloworld = myplugs.helloworld',
     224+        ],
     225+    },
     226 )
     227}}}
     228 }}}
     229}}}
     230{{{#!td
     231'''`#!diff`''' has a particularly nice renderer:
     232 {{{
     233#!diff
     234--- Version 55
     235+++ Version 56
     236@@ -115,8 +115,9 @@
     237     name='TracHelloWorld', version='1.0',
     238     packages=find_packages(exclude=['*.tests*']),
     239-    entry_points = """
     240-        [trac.plugins]
     241-        helloworld = myplugs.helloworld
     242-    """,
     243+    entry_points = {
     244+        'trac.plugins': [
     245+            'helloworld = myplugs.helloworld',
     246+        ],
     247+    },
     248 )
     249 }}}
     250}}}
     251{{{#!comment
     252Uncomment for Trac 1.2 release.
     253{{{
     254{{{#!python lineno=3 marks=3,9-10,16
     255def expand_markup(stream, ctxt=None):
     256    """A Genshi stream filter for expanding `genshi.Markup` events.
     257
     258    Note: Expansion may not be possible if the fragment is badly
     259    formed, or partial.
     260    """
     261    for event in stream:
     262        if isinstance(event[1], Markup):
     263            try:
     264                for subevent in HTML(event[1]):
     265                    yield subevent
     266            except ParseError:
     267                yield event
     268        else:
     269            yield event
     270}}}
     271}}}
     272Line numbers can be added to code blocks and lines can be highlighted //(since 1.1.2)//.
     273{{{#!python lineno=3 marks=3,9-10,16
     274def expand_markup(stream, ctxt=None):
     275    """A Genshi stream filter for expanding `genshi.Markup` events.
     276
     277    Note: Expansion may not be possible if the fragment is badly
     278    formed, or partial.
     279    """
     280    for event in stream:
     281        if isinstance(event[1], Markup):
     282            try:
     283                for subevent in HTML(event[1]):
     284                    yield subevent
     285            except ParseError:
     286                yield event
     287        else:
     288            yield event
     289}}}
     290}}}
     291
     292For more processor macros developed and/or contributed by users, visit:
     293 * [trac:ProcessorBazaar]
     294 * [trac:MacroBazaar]
     295 * [http://trac-hacks.org Trac Hacks] community site
     296
     297Developing processors is no different from Wiki macros.
     298In fact they work the same way, only the usage syntax differs.
     299See WikiMacros#DevelopingCustomMacros for more information.
     300
     301
     302----
     303See also: WikiMacros, WikiHtml, WikiRestructuredText, TracSyntaxColoring, WikiFormatting, TracGuide