Edgewall Software

Changes between Version 13 and Version 14 of WikiHtml


Ignore:
Timestamp:
Apr 10, 2010, 7:31:30 PM (14 years ago)
Author:
Christian Boos
Comment:

copied from 0.12/WikiHtml@10

Legend:

Unmodified
Added
Removed
Modified
  • WikiHtml

    v13 v14  
     1** Note: this page documents the 0.12 version of Trac, see [[0.11/WikiHtml]] if you need the previous version **
    12= Using HTML in Wiki Text =
    23
    3 Trac supports inserting HTML into any wiki context, accomplished using the HTML [wiki:WikiProcessors WikiProcessor].
    4 
    5 HTML support is built-in, and does not require installing any additional packages.
    6 
    7 == How to Use HTML ==
     4Trac supports inserting HTML into any wiki context, accomplished using the `#!html` [wiki:WikiProcessors WikiProcessor].
     5
     6However a constraint is that this HTML has to be well-formed.
     7In particular you can't insert a start tag in an `#!html` block,
     8resume normal wiki text and insert the corresponding end tag in a
     9second `#!html` block.
     10
     11Fortunately, for creating styled <div>s, <span>s  or even complex tables
     12containing arbitrary Wiki text, there's a powerful alternative: use of
     13dedicated `#!div`, `#!span` and `#!table`, `#!tr`, `#!td` and `#!th` blocks.
     14
     15Those Wiki processors are built-in, and does not require installing any additional packages.
     16
     17== How to use `#!html` == #HowtoUseHTML
    818To inform the wiki engine that a block of text should be treated as HTML, use the ''html'' processor.
    919
    10 This example should explain:
     20||= Wiki Markup =||= Display =||
     21{{{#!td
     22  {{{
     23  {{{
     24  #!html
     25  <h1 style="text-align: right; color: blue">HTML Test</h1>
     26  }}}
     27  }}}
     28}}}
     29{{{#!td style="padding-left: 2em"
     30  {{{
     31  #!html
     32  <h1 style="text-align: right; color: blue">HTML Test</h1>
     33  }}}
     34}}}
     35
     36Note 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.
     37
     38Since 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.
     39The new way to wrap any wiki content inside a <div> is to use the `#!div` Wiki  processor.
     40
     41== How to use `#!div` and `#!span` == #HowtoUseDivSpan
     42
     43||= Wiki Markup =||= Display =||
     44{{{#!td
     45  {{{
     46  {{{
     47  #!div class="important" style="border: 2pt solid; text-align: center"
     48  This is the ''only'' way to go in Trac 0.11
     49  }}}
     50
     51  {{{
     52  #!div class="wikipage" style="border: 1pt dotted"
     53  Only `wikipage` (same as specifying no class attribute)
     54  }}}
     55
     56  {{{
     57  #!div class="wikipage compact " style="border: 1pt solid"
     58  Use combined classes (`compact` and `wikipage`)
     59  }}}
     60
     61  {{{
     62  #!div class="compact" style="border: 1pt dotted"
     63  Only `compact`
     64  }}}
     65
     66  {{{
     67  #!div class="" style="border: 1pt solid"
     68  No classes (//not// the same as specifying no class attribute...)
     69  }}}
     70  }}}
     71}}}
     72{{{#!td style="padding-left: 2em"
     73  {{{
     74  #!div class="important" style="border: 2pt solid; text-align: center"
     75  This is the ''only'' way to go in Trac 0.11
     76  }}}
     77
     78  {{{
     79  #!div class="wikipage" style="border: 1pt dotted"
     80  Only `wikipage` (same as specifying no class attribute)
     81  }}}
     82
     83  {{{
     84  #!div class="wikipage compact " style="border: 1pt solid"
     85  Use combined classes (`compact` and `wikipage`)
     86  }}}
     87
     88  {{{
     89  #!div class="compact" style="border: 1pt dotted"
     90  Only compact
     91  }}}
     92
     93  {{{
     94  #!div class="" style="border: 1pt solid"
     95  No classes (//not// the same as specifying no class attribute...)
     96  }}}
     97}}}
     98
     99Note 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.
     100
     101For spans, you should rather use the Macro call syntax:
     102||= Wiki Markup =||
     103{{{#!td
     104  {{{
     105  Hello
     106  [[span(''WORLD'' (click [#anchor here]), style=color: green; font-size: 120%, id=anchor)]]!
     107  }}}
     108}}}
     109|---------------------------------------------------------------------------------
     110||= Display =||
     111{{{#!td style="padding-left: 2em"
     112  Hello
     113  [[span(''WORLD'' (click [#anchor here]), style=color: green; font-size: 120%, id=anchor)]]!
     114}}}
     115
     116== How to use `#!td` and other table related processors == #Tables
     117
     118`#!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.
     119
     120||= Wiki Markup =||= Display =||
     121{{{#!td
     122 {{{
     123 Simple 2x2 table with rich content:
     124 {{{#!th align=left
     125  - Left
     126  - Header
     127 }}}
     128 {{{#!th align=left
     129  - Right
     130  - Header
     131 }}}
     132 |----------------------------------
     133 {{{#!td style="background: #ffd"
     134  - Left
     135  - Content
     136 }}}
     137 {{{#!td style="vertical-align: top"
     138 !RightContent
     139 }}}
     140 |----------------------------------
     141 || ... and this can be mixed||\
     142 ||with pipe-based cells ||
     143 {{{#!td colspan=2
     144 Pick the style the more appropriate
     145 to your content
     146 
     147 See WikiFormatting#Tables for details
     148 on the pipe-based table syntax.
     149 }}}
     150 
     151 If one needs to add some
     152 attributes to the table itself...
     153 
     154 {{{
     155 #!table style="border:none;text-align:center;margin:auto"
     156   {{{#!tr ====================================
     157     {{{#!th style="border: none"
     158     Left header
     159     }}}
     160     {{{#!th style="border: none"
     161     Right header
     162     }}}
     163   }}}
     164   {{{#!tr ==== style="border: 1px dotted grey"
     165     {{{#!td style="border: none"
     166     1.1
     167     }}}
     168     {{{#!td style="border: none"
     169     1.2
     170     }}}
     171   }}}
     172   {{{#!tr ====================================
     173     {{{#!td style="border: none"
     174     2.1
     175     }}}
     176     {{{#!td
     177     2.2
     178     }}}
     179   }}}
     180 }}}
     181
     182
     183 }}}
     184}}}
     185{{{#!td valign=top
     186Simple 2x2 table with rich content:
     187{{{#!th align=left
     188 - Left
     189 - Header
     190}}}
     191{{{#!th align=left
     192 - Right
     193 - Header
     194}}}
     195|----------------------------------
     196{{{#!td style="background: #ffd"
     197 - Left
     198 - Content
     199}}}
     200{{{#!td style="vertical-align: top"
     201!RightContent
     202}}}
     203|----------------------------------
     204|| ... and this can be mixed||\
     205||with pipe-based cells ||
     206{{{#!td colspan=2
     207Pick the style the more appropriate
     208to your content
     209
     210See WikiFormatting#Tables for details
     211on the pipe-based table syntax.
     212}}}
     213
     214If one needs to add some
     215attributes to the table itself...
     216
    11217{{{
    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>
    17 }}}
    18 
    19 Results in:
    20 {{{
    21 #!html
    22 <h1 style="text-align: right; color: blue">HTML Test</h1>
    23 }}}
    24 
    25 Note 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.
    26 
    27 Since 0.11, the filtering is done by Genshi, and as such, the produced output 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.
    28 The new way to wrap any wiki content inside a <div> is to use the ''div'' Wiki  processor:
    29 
    30 {{{
    31 {{{
    32 #!div class=important style="border: 2pt solid; text-align: center"
    33 This is the ''only'' way to go in Trac 0.11
    34 }}}
    35 }}}
    36 
    37 Results in:
    38 {{{
    39 #!div class=important style="border: 2pt solid; text-align: center"
    40 This is the ''only'' way to go in Trac 0.11
    41 }}}
    42 
    43 Note that if you don't specify a CSS class, the `wikipage` class will be added, so that the special layout of headers is respected in the <div>. If you specify explicitly the padding property, you have to take this into account (tip: [http://getfirebug.com/ get FireBug]!).
    44 
    45 For spans, you should rather use the Macro call syntax:
    46 {{{
    47  Hello [[span(''WORLD'' (click [#world-anchor here]), style=color: green; font-size: 120%, id=world-anchor)]]!
    48 }}}
    49 
    50 Results in:
    51  Hello [[span(''WORLD'' (click [#world-anchor here]), style=color: green; font-size: 120%, id=world-anchor)]]!
    52 
    53 
    54 == Images ==
    55 If you want display an image inline, append the following: '''?format=raw''' after the file name.  For example, to display the Trac logo inline, use this syntax:
    56 
    57 {{{
    58  <img src="http://www.edgewall.org/gfx/trac_logo.png?format=raw" />
    59 }}}
    60 
    61 {{{
    62 #!html
    63 <img src="http://www.edgewall.org/gfx/trac_logo.png?format=raw" />
    64 }}}
    65 
     218#!table style="border:none;text-align:center;margin:auto"
     219  {{{#!tr ====================================
     220    {{{#!th style="border: none"
     221    Left header
     222    }}}
     223    {{{#!th style="border: none"
     224    Right header
     225    }}}
     226  }}}
     227  {{{#!tr ==== style="border: 1px dotted grey"
     228    {{{#!td style="border: none"
     229    1.1
     230    }}}
     231    {{{#!td style="border: none"
     232    1.2
     233    }}}
     234  }}}
     235  {{{#!tr ====================================
     236    {{{#!td style="border: none"
     237    2.1
     238    }}}
     239    {{{#!td
     240    2.2
     241    }}}
     242  }}}
     243}}}
     244}}}
     245
     246Note 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.
     247
     248{{{#!table class=""
     249||= Wiki Markup =||= Display =||
     250 {{{#!td
     251  {{{
     252  {{{#!table class=""
     253  ||  0||  1||  2||
     254  || 10|| 20|| 30||
     255  || 11|| 22|| 33||
     256  ||||||=  numbers  =||
     257  }}}
     258  }}}
     259 }}}
     260 {{{#!td
     261  {{{#!table class=""
     262  ||  0||  1||  2||
     263  || 10|| 20|| 30||
     264  || 11|| 22|| 33||
     265  ||||||=  numbers  =||
     266  }}}
     267 }}}
     268}}}
     269
     270Other classes can be specified as alternatives (remember that you can define your own in [TracInterfaceCustomization#SiteAppearance site/style.css]).
     271
     272||= Wiki Markup =||= Display =||
     273{{{#!td
     274  {{{
     275  {{{#!table class="listing"
     276  ||  0||  1||  2||
     277  || 10|| 20|| 30||
     278  || 11|| 22|| 33||
     279  ||||||=  numbers  =||
     280  }}}
     281  }}}
     282}}}
     283{{{#!td
     284  {{{#!table class="listing"
     285  ||  0||  1||  2||
     286  || 10|| 20|| 30||
     287  || 11|| 22|| 33||
     288  ||||||=  numbers  =||
     289  }}}
     290}}}
     291
     292
     293== HTML comments ==
     294HTML 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:
     295||= Wiki Markup =||
     296{{{#!td
     297  {{{
     298  {{{
     299  #!htmlcomment
     300  This block is translated to an HTML comment.
     301  It can contain <tags> and &entities; that will not be escaped in the output.
     302  }}}
     303  }}}
     304}}}
     305|---------------------------------------------------------------------------------
     306||= Display =||
     307{{{#!td
     308  {{{
     309  <!--
     310  This block is translated to an HTML comment.
     311  It can contain <tags> and &entities; that will not be escaped in the output.
     312  -->
     313  }}}
     314}}}
     315
     316Please note that the character sequence "--" is not allowed in HTML comments, and will generate a rendering error.
    66317
    67318