Changes between Version 4 and Version 5 of WikiHtml


Ignore:
Timestamp:
Apr 13, 2010, 3:53:03 AM (10 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WikiHtml

    v4 v5  
    11= Using HTML in Wiki Text =
    22
    3 Trac supports inserting HTML into any wiki context, accomplished using the `#!html` [wiki:WikiProcessors WikiProcessor].
     3Trac supports inserting HTML into any wiki context, accomplished using the HTML [wiki:WikiProcessors WikiProcessor].
    44
    5 However a constraint is that this HTML has to be well-formed.
    6 In particular you can't insert a start tag in an `#!html` block,
    7 resume normal wiki text and insert the corresponding end tag in a
    8 second `#!html` block.
     5HTML support is built-in, and does not require installing any additional packages.
    96
    10 Fortunately, for creating styled <div>s, <span>s  or even complex tables
    11 containing arbitrary Wiki text, there's a powerful alternative: use of
    12 dedicated `#!div`, `#!span` and `#!table`, `#!tr`, `#!td` and `#!th` blocks.
    13 
    14 Those Wiki processors are built-in, and does not require installing any additional packages.
    15 
    16 == How to use `#!html` == #HowtoUseHTML
     7== How to Use HTML ==
    178To inform the wiki engine that a block of text should be treated as HTML, use the ''html'' processor.
    189
    19 ||= Wiki Markup =||= Display =||
    20 {{{#!td
    21   {{{
    22   {{{
    23   #!html
    24   <h1 style="text-align: right; color: blue">HTML Test</h1>
    25   }}}
    26   }}}
     10This example should explain:
     11{{{
     12#!html
     13<pre class="wiki">{{{
     14#!html
     15&lt;h1 style="text-align: right; color: blue"&gt;HTML Test&lt;/h1&gt;
     16}}}</pre>
    2717}}}
    28 {{{#!td style="padding-left: 2em"
    29   {{{
    30   #!html
    31   <h1 style="text-align: right; color: blue">HTML Test</h1>
    32   }}}
     18
     19Results in:
     20{{{
     21#!html
     22<h1 style="text-align: right; color: blue">HTML Test</h1>
    3323}}}
    3424
    3525Note that Trac sanitizes your HTML code before displaying it. That means that if you try to use potentially dangerous constructs such as Javascript event handlers, those will be removed from the output.
    3626
    37 Since 0.11, the filtering is done by Genshi, and as such, the produced output will be a well-formed fragment of HTML. As noted above in the introduction, this mean that you can no longer use two HTML blocks, one for opening a <div>, the second for closing it, in order to wrap arbitrary wiki text.
    38 The new way to wrap any wiki content inside a <div> is to use the `#!div` Wiki  processor.
    39 
    40 == How to use `#!div` and `#!span` == #HowtoUseDivSpan
    41 
    42 ||= Wiki Markup =||= Display =||
    43 {{{#!td
    44   {{{
    45   {{{
    46   #!div class="important" style="border: 2pt solid; text-align: center"
    47   This is the ''only'' way to go in Trac 0.11
    48   }}}
    49 
    50   {{{
    51   #!div class="wikipage" style="border: 1pt dotted"
    52   Only `wikipage` (same as specifying no class attribute)
    53   }}}
    54 
    55   {{{
    56   #!div class="wikipage compact " style="border: 1pt solid"
    57   Use combined classes (`compact` and `wikipage`)
    58   }}}
    59 
    60   {{{
    61   #!div class="compact" style="border: 1pt dotted"
    62   Only `compact`
    63   }}}
    64 
    65   {{{
    66   #!div class="" style="border: 1pt solid"
    67   No classes (//not// the same as specifying no class attribute...)
    68   }}}
    69   }}}
    70 }}}
    71 {{{#!td style="padding-left: 2em"
    72   {{{
    73   #!div class="important" style="border: 2pt solid; text-align: center"
    74   This is the ''only'' way to go in Trac 0.11
    75   }}}
    76 
    77   {{{
    78   #!div class="wikipage" style="border: 1pt dotted"
    79   Only `wikipage` (same as specifying no class attribute)
    80   }}}
    81 
    82   {{{
    83   #!div class="wikipage compact " style="border: 1pt solid"
    84   Use combined classes (`compact` and `wikipage`)
    85   }}}
    86 
    87   {{{
    88   #!div class="compact" style="border: 1pt dotted"
    89   Only compact
    90   }}}
    91 
    92   {{{
    93   #!div class="" style="border: 1pt solid"
    94   No classes (//not// the same as specifying no class attribute...)
    95   }}}
    96 }}}
    97 
    98 Note that the contents of a `#!div` block are contained in one or more paragraphs, which have a non-zero top and bottom margin. This leads to the top and bottom padding in the example above. To remove the top and bottom margin of the contents, add the `compact` class to the `#!div`. Another predefined class besides `wikipage` and `compact` is `important`, which can be used to make a paragraph stand out. Extra CSS classes can be defined via the `site/style.css` file for example, see TracInterfaceCustomization#SiteAppearance.
    99 
    100 For spans, you should rather use the Macro call syntax:
    101 ||= Wiki Markup =||
    102 {{{#!td
    103   {{{
    104   Hello
    105   [[span(''WORLD'' (click [#anchor here]), style=color: green; font-size: 120%, id=anchor)]]!
    106   }}}
    107 }}}
    108 |---------------------------------------------------------------------------------
    109 ||= Display =||
    110 {{{#!td style="padding-left: 2em"
    111   Hello
    112   [[span(''WORLD'' (click [#anchor here]), style=color: green; font-size: 120%, id=anchor)]]!
    113 }}}
    114 
    115 == How to use `#!td` and other table related processors == #Tables
    116 
    117 `#!td` or `#!th` processors are actually the main ones, for creating table data and header cells, respectively. The other processors `#!table` and `#!tr` are not required for introducing a table structure, as `#!td` and `#!th` will do this automatically. The `|-` row separator can be used to start a new row when needed, but some may prefer to use a `#!tr` block for that, as this introduces a more formal grouping and offers the possibility to use an extra level of indentation. The main purpose of the `#!table` and `#!tr` is to give the possibility to specify HTML attributes, like ''style'' or ''valign'' to these elements.
    118 
    119 ||= Wiki Markup =||= Display =||
    120 {{{#!td
    121  {{{
    122  Simple 2x2 table with rich content:
    123  {{{#!th align=left
    124   - Left
    125   - Header
    126  }}}
    127  {{{#!th align=left
    128   - Right
    129   - Header
    130  }}}
    131  |----------------------------------
    132  {{{#!td style="background: #ffd"
    133   - Left
    134   - Content
    135  }}}
    136  {{{#!td style="vertical-align: top"
    137  !RightContent
    138  }}}
    139  |----------------------------------
    140  || ... and this can be mixed||\
    141  ||with pipe-based cells ||
    142  {{{#!td colspan=2
    143  Pick the style the more appropriate
    144  to your content
    145  
    146  See WikiFormatting#Tables for details
    147  on the pipe-based table syntax.
    148  }}}
    149  
    150  If one needs to add some
    151  attributes to the table itself...
    152  
    153  {{{
    154  #!table style="border:none;text-align:center;margin:auto"
    155    {{{#!tr ====================================
    156      {{{#!th style="border: none"
    157      Left header
    158      }}}
    159      {{{#!th style="border: none"
    160      Right header
    161      }}}
    162    }}}
    163    {{{#!tr ==== style="border: 1px dotted grey"
    164      {{{#!td style="border: none"
    165      1.1
    166      }}}
    167      {{{#!td style="border: none"
    168      1.2
    169      }}}
    170    }}}
    171    {{{#!tr ====================================
    172      {{{#!td style="border: none"
    173      2.1
    174      }}}
    175      {{{#!td
    176      2.2
    177      }}}
    178    }}}
    179  }}}
    180 
    181 
    182  }}}
    183 }}}
    184 {{{#!td valign=top
    185 Simple 2x2 table with rich content:
    186 {{{#!th align=left
    187  - Left
    188  - Header
    189 }}}
    190 {{{#!th align=left
    191  - Right
    192  - Header
    193 }}}
    194 |----------------------------------
    195 {{{#!td style="background: #ffd"
    196  - Left
    197  - Content
    198 }}}
    199 {{{#!td style="vertical-align: top"
    200 !RightContent
    201 }}}
    202 |----------------------------------
    203 || ... and this can be mixed||\
    204 ||with pipe-based cells ||
    205 {{{#!td colspan=2
    206 Pick the style the more appropriate
    207 to your content
    208 
    209 See WikiFormatting#Tables for details
    210 on the pipe-based table syntax.
    211 }}}
    212 
    213 If one needs to add some
    214 attributes to the table itself...
     27Since 0.11, the filtering is done by Genshi, and as such, the produced out will be a well-formed fragment of HTML. In other words, this mean that you can no longer use two HTML blocks, one for opening a <div>, the second for closing it, in order to wrap arbitrary wiki text.
     28To achieve this, you need now to use the ''div'' Wiki processor:
    21529
    21630{{{
    217 #!table style="border:none;text-align:center;margin:auto"
    218   {{{#!tr ====================================
    219     {{{#!th style="border: none"
    220     Left header
    221     }}}
    222     {{{#!th style="border: none"
    223     Right header
    224     }}}
    225   }}}
    226   {{{#!tr ==== style="border: 1px dotted grey"
    227     {{{#!td style="border: none"
    228     1.1
    229     }}}
    230     {{{#!td style="border: none"
    231     1.2
    232     }}}
    233   }}}
    234   {{{#!tr ====================================
    235     {{{#!td style="border: none"
    236     2.1
    237     }}}
    238     {{{#!td
    239     2.2
    240     }}}
    241   }}}
     31{{{
     32#!div class=important style="border: 2pt solid; text-align: center"
     33This is the ''only'' way to go in Trac 0.11
    24234}}}
    24335}}}
    24436
    245 Note that by default tables are assigned the "wiki" CSS class, which gives a distinctive look to the header cells and a default border to the table and cells (as can be seen for the tables on this page). By removing this class (`#!table class=""`), one regains complete control on the table presentation. In particular, neither the table, the rows nor the cells will have a border, so this is a more effective way to get such an effect than having to specify a `style="border: no"` parameter everywhere.
    246 
    247 {{{#!table class=""
    248 ||= Wiki Markup =||= Display =||
    249  {{{#!td
    250   {{{
    251   {{{#!table class=""
    252   ||  0||  1||  2||
    253   || 10|| 20|| 30||
    254   || 11|| 22|| 33||
    255   ||||||=  numbers  =||
    256   }}}
    257   }}}
    258  }}}
    259  {{{#!td
    260   {{{#!table class=""
    261   ||  0||  1||  2||
    262   || 10|| 20|| 30||
    263   || 11|| 22|| 33||
    264   ||||||=  numbers  =||
    265   }}}
    266  }}}
     37Results in:
     38{{{
     39#!div class=important style="border: 2pt solid; text-align: center"
     40This is the ''only'' way to go in Trac 0.11
    26741}}}
    26842
    269 Other classes can be specified as alternatives (remember that you can define your own in [TracInterfaceCustomization#SiteAppearance site/style.css]).
    270 
    271 ||= Wiki Markup =||= Display =||
    272 {{{#!td
    273   {{{
    274   {{{#!table class="listing"
    275   ||  0||  1||  2||
    276   || 10|| 20|| 30||
    277   || 11|| 22|| 33||
    278   ||||||=  numbers  =||
    279   }}}
    280   }}}
    281 }}}
    282 {{{#!td
    283   {{{#!table class="listing"
    284   ||  0||  1||  2||
    285   || 10|| 20|| 30||
    286   || 11|| 22|| 33||
    287   ||||||=  numbers  =||
    288   }}}
     43For spans, you should rather use the Macro call syntax:
     44{{{
     45 Hello [[span(''WORLD'' (click [#world-anchor here]), style=color: green; font-size: 120%, id=world-anchor)]]!
    28946}}}
    29047
    291 
    292 == HTML comments ==
    293 HTML comments are stripped from the output of the `html` processor. To add an HTML comment to a wiki page, use the `htmlcomment` processor (available since 0.12). For example, the following code block:
    294 ||= Wiki Markup =||
    295 {{{#!td
    296   {{{
    297   {{{
    298   #!htmlcomment
    299   This block is translated to an HTML comment.
    300   It can contain <tags> and &entities; that will not be escaped in the output.
    301   }}}
    302   }}}
    303 }}}
    304 |---------------------------------------------------------------------------------
    305 ||= Display =||
    306 {{{#!td
    307   {{{
    308   <!--
    309   This block is translated to an HTML comment.
    310   It can contain <tags> and &entities; that will not be escaped in the output.
    311   -->
    312   }}}
    313 }}}
    314 
    315 Please note that the character sequence "--" is not allowed in HTML comments, and will generate a rendering error.
     48Results in:
     49 Hello [[span(''WORLD'' (click [#world-anchor here]), style=color: green; font-size: 120%, id=world-anchor)]]!
    31650
    31751

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png