1 | | = Using HTML in Wiki Text = |
2 | | |
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 == |
8 | | To inform the wiki engine that a block of text should be treated as HTML, use the ''html'' processor. |
9 | | |
10 | | This example should explain: |
11 | | {{{ |
12 | | #!html |
13 | | <pre class="wiki">{{{ |
14 | | #!html |
15 | | <h1 style="text-align: right; color: blue">HTML Test</h1> |
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 | | |
66 | | |
67 | | |
68 | | == More Information == |
69 | | |
70 | | * http://www.w3.org/ -- World Wide Web Consortium |
71 | | * http://www.w3.org/MarkUp/ -- HTML Markup Home Page |
| 1 | = Using HTML in Wiki Text |
| 2 | |
| 3 | Trac supports the display of HTML in any wiki context, by using the `#!html` [wiki:WikiProcessors WikiProcessor]. |
| 4 | |
| 5 | However, this HTML has to be [https://en.wikipedia.org/wiki/Well-formed_element well-formed]. |
| 6 | In particular, you can't insert a start tag in an `#!html` block, resume normal wiki text and insert the corresponding end tag in a second `#!html` block. |
| 7 | |
| 8 | For creating styled `<div>`s, `<span>`s or even complex tables containing arbitrary Wiki text, there is a powerful alternative: `#!div`, `#!span` and `#!table`, `#!tr`, `#!td` and `#!th` blocks. Those Wiki processors are built-in and do not require additional packages to be installed. |
| 9 | |
| 10 | == How to use `#!html` #HowtoUseHTML |
| 11 | To inform the wiki engine that a block of text should be treated as HTML, use the ''html'' processor: |
| 12 | |
| 13 | ||= Wiki Markup =||= Display =|| |
| 14 | {{{#!td |
| 15 | {{{ |
| 16 | {{{#!html |
| 17 | <h1 style="text-align: right; color: blue">HTML Test</h1> |
| 18 | }}} |
| 19 | }}} |
| 20 | }}} |
| 21 | {{{#!td style="padding-left: 2em" |
| 22 | {{{#!html |
| 23 | <h1 style="text-align: right; color: blue">HTML Test</h1> |
| 24 | }}} |
| 25 | }}} |
| 26 | |
| 27 | Note that Trac sanitizes your HTML code before displaying it. That means that potentially dangerous constructs, such as Javascript event handlers, will be removed from the output. |
| 28 | |
| 29 | The filtering is done by [https://genshi.edgewall.org/ Genshi] and the output will be a well-formed fragment of HTML. This means that you cannot use two HTML blocks, one for opening a <div> and another for closing it, in order to wrap arbitrary wiki text. |
| 30 | |
| 31 | == How to use `#!div` and `#!span` == #HowtoUseDivSpan |
| 32 | |
| 33 | ||= Wiki Markup =||= Display =|| |
| 34 | {{{#!td |
| 35 | {{{ |
| 36 | {{{#!div class="important" |
| 37 | **important** is a predefined class. |
| 38 | }}} |
| 39 | }}} |
| 40 | {{{ |
| 41 | {{{#!div style="border: 1pt dotted; margin: 1em" |
| 42 | **wikipage** is another predefined class that will |
| 43 | be used when no class is specified. |
| 44 | }}} |
| 45 | }}} |
| 46 | {{{ |
| 47 | {{{#!div class="compact" style="border: 1pt dotted; margin: 1em" |
| 48 | **compact** is another predefined class reducing |
| 49 | the padding within the `<div>` to a minimum. |
| 50 | }}} |
| 51 | }}} |
| 52 | {{{ |
| 53 | {{{#!div class="wikipage compact" style="border: 1pt dotted" |
| 54 | Classes can be combined (here **wikipage** and **compact**) |
| 55 | which results in this case in reduced //vertical// |
| 56 | padding but there's still some horizontal space for coping |
| 57 | with headings. |
| 58 | }}} |
| 59 | }}} |
| 60 | {{{ |
| 61 | {{{#!div class="" style="border: 1pt dotted; margin: 1em" |
| 62 | Explicitly specifying no classes is //not// the same |
| 63 | as specifying no class attribute, as this will remove |
| 64 | the //wikipage// default class. |
| 65 | }}} |
| 66 | }}} |
| 67 | }}} |
| 68 | {{{#!td style="padding-left: 2em" |
| 69 | |
| 70 | {{{#!div class="important" |
| 71 | **important** is a predefined class. |
| 72 | }}} |
| 73 | |
| 74 | {{{#!div style="border: 1pt dotted; margin: 1em" |
| 75 | **wikipage** is another predefined class that will |
| 76 | be used when no class is specified. |
| 77 | }}} |
| 78 | |
| 79 | {{{#!div class="compact" style="border: 1pt dotted; margin: 1em" |
| 80 | **compact** is another predefined class reducing |
| 81 | the padding within the `<div>` to a minimum. |
| 82 | }}} |
| 83 | |
| 84 | {{{#!div class="wikipage compact" style="border: 1pt dotted" |
| 85 | Classes can be combined (here **wikipage** and **compact**) |
| 86 | which results in this case in reduced //vertical// |
| 87 | padding but there's still some horizontal space for coping |
| 88 | with headings. |
| 89 | }}} |
| 90 | |
| 91 | {{{#!div class="" style="border: 1pt dotted; margin: 1em" |
| 92 | Explicitly specifying no classes is //not// the same |
| 93 | as specifying no class attribute, as this will remove |
| 94 | the //wikipage// default class. |
| 95 | }}} |
| 96 | |
| 97 | }}} |
| 98 | |
| 99 | 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 content, 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 [TracInterfaceCustomization#SiteAppearance site/style.css]. |
| 100 | |
| 101 | For spans, you should 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 | The `#!td` or `#!th` processors should be used to create table data and table 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 | {{{#!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... |
| 215 | |
| 216 | {{{#!table style="border:none;text-align:center;margin:auto" |
| 217 | {{{#!tr ==================================== |
| 218 | {{{#!th style="border: none" |
| 219 | Left header |
| 220 | }}} |
| 221 | {{{#!th style="border: none" |
| 222 | Right header |
| 223 | }}} |
| 224 | }}} |
| 225 | {{{#!tr ==== style="border: 1px dotted grey" |
| 226 | {{{#!td style="border: none" |
| 227 | 1.1 |
| 228 | }}} |
| 229 | {{{#!td style="border: none" |
| 230 | 1.2 |
| 231 | }}} |
| 232 | }}} |
| 233 | {{{#!tr ==================================== |
| 234 | {{{#!td style="border: none" |
| 235 | 2.1 |
| 236 | }}} |
| 237 | {{{#!td |
| 238 | 2.2 |
| 239 | }}} |
| 240 | }}} |
| 241 | }}} |
| 242 | }}} |
| 243 | |
| 244 | 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 nor the rows nor the cells will have a border, so this is a more effective way to get such an effect rather than having to specify a `style="border: no"` parameter everywhere. |
| 245 | |
| 246 | {{{#!table class="" |
| 247 | ||= Wiki Markup =||= Display =|| |
| 248 | {{{#!td |
| 249 | {{{ |
| 250 | {{{#!table class="" |
| 251 | || 0|| 1|| 2|| |
| 252 | || 10|| 20|| 30|| |
| 253 | || 11|| 22|| 33|| |
| 254 | ||||||= numbers =|| |
| 255 | }}} |
| 256 | }}} |
| 257 | }}} |
| 258 | {{{#!td |
| 259 | {{{#!table class="" |
| 260 | || 0|| 1|| 2|| |
| 261 | || 10|| 20|| 30|| |
| 262 | || 11|| 22|| 33|| |
| 263 | ||||||= numbers =|| |
| 264 | }}} |
| 265 | }}} |
| 266 | }}} |
| 267 | |
| 268 | Other classes can be specified as alternatives (remember that you can define your own in [TracInterfaceCustomization#SiteAppearance site/style.css]). |
| 269 | |
| 270 | ||= Wiki Markup =||= Display =|| |
| 271 | {{{#!td |
| 272 | {{{ |
| 273 | {{{#!table class="listing" |
| 274 | || 0|| 1|| 2|| |
| 275 | || 10|| 20|| 30|| |
| 276 | || 11|| 22|| 33|| |
| 277 | ||||||= numbers =|| |
| 278 | }}} |
| 279 | }}} |
| 280 | }}} |
| 281 | {{{#!td |
| 282 | {{{#!table class="listing" |
| 283 | || 0|| 1|| 2|| |
| 284 | || 10|| 20|| 30|| |
| 285 | || 11|| 22|| 33|| |
| 286 | ||||||= numbers =|| |
| 287 | }}} |
| 288 | }}} |
| 289 | |
| 290 | == HTML comments |
| 291 | 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 Trac 0.12: |
| 292 | ||= Wiki Markup =|| |
| 293 | {{{#!td |
| 294 | {{{ |
| 295 | {{{#!htmlcomment |
| 296 | This block is translated to an HTML comment. |
| 297 | It can contain <tags> and &entities; that will not be escaped in the output. |
| 298 | }}} |
| 299 | }}} |
| 300 | }}} |
| 301 | |--------------------------------------------------------------------------------- |
| 302 | ||= Display =|| |
| 303 | {{{#!td |
| 304 | {{{ |
| 305 | <!-- |
| 306 | This block is translated to an HTML comment. |
| 307 | It can contain <tags> and &entities; that will not be escaped in the output. |
| 308 | --> |
| 309 | }}} |
| 310 | }}} |
| 311 | |
| 312 | The character sequence `--` is not allowed in HTML comments, and will generate a rendering error. |
| 313 | |
| 314 | |
| 315 | == More Information |
| 316 | |
| 317 | * https://www.w3.org/ -- World Wide Web Consortium |
| 318 | * https://www.w3.org/MarkUp/ -- HTML Markup Home Page |