Changes between Version 3 and Version 4 of WikiHtml


Ignore:
Timestamp:
05/30/11 20:20:24 (13 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WikiHtml

    v3 v4  
    11= Using HTML in Wiki Text = 
    22 
    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 == 
     3Trac supports inserting HTML into any wiki context, accomplished using the `#!html` [wiki:WikiProcessors WikiProcessor].  
     4 
     5However a constraint is that this HTML has to be well-formed. 
     6In particular you can't insert a start tag in an `#!html` block, 
     7resume normal wiki text and insert the corresponding end tag in a  
     8second `#!html` block.  
     9 
     10Fortunately, for creating styled <div>s, <span>s  or even complex tables 
     11containing arbitrary Wiki text, there's a powerful alternative: use of 
     12dedicated `#!div`, `#!span` and `#!table`, `#!tr`, `#!td` and `#!th` blocks. 
     13 
     14Those Wiki processors are built-in, and does not require installing any additional packages. 
     15 
     16== How to use `#!html` == #HowtoUseHTML 
    817To inform the wiki engine that a block of text should be treated as HTML, use the ''html'' processor.  
    918 
    10 This example should explain: 
     19||= Wiki Markup =||= Display =|| 
     20{{{#!td 
     21  {{{ 
     22  {{{ 
     23  #!html 
     24  <h1 style="text-align: right; color: blue">HTML Test</h1> 
     25  }}} 
     26  }}} 
     27}}} 
     28{{{#!td style="padding-left: 2em" 
     29  {{{ 
     30  #!html 
     31  <h1 style="text-align: right; color: blue">HTML Test</h1> 
     32  }}} 
     33}}} 
     34 
     35Note 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.  
     36 
     37Since 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. 
     38The 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 
     98Note 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 
     100For 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 
     185Simple 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 
     206Pick the style the more appropriate 
     207to your content 
     208 
     209See WikiFormatting#Tables for details 
     210on the pipe-based table syntax. 
     211}}} 
     212 
     213If one needs to add some  
     214attributes to the table itself... 
     215 
    11216{{{ 
    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 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. 
    28 To achieve this, you need now 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 For 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)]]! 
    46 }}} 
    47  
    48 Results in: 
    49  Hello [[span(''WORLD'' (click [#world-anchor here]), style=color: green; font-size: 120%, id=world-anchor)]]! 
     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  }}} 
     242}}} 
     243}}} 
     244 
     245Note 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 }}} 
     267}}} 
     268 
     269Other 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  }}} 
     289}}} 
     290 
     291 
     292== HTML comments == 
     293HTML 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 
     315Please note that the character sequence "--" is not allowed in HTML comments, and will generate a rendering error. 
    50316 
    51317