Context Navigation

Using HTML in Wiki Text

Trac supports the display of HTML in any wiki context, by using the #!htmlWikiProcessor.

However, this HTML has to be ​well-formed.
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.

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.

How to use #!html

To inform the wiki engine that a block of text should be treated as HTML, use the html processor:

HTML Test

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.

The filtering is done by ​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.

How to use #!div and #!span

Wiki Markup

Display

{{{#!div class="important"
**important** is a predefined class.
}}}

{{{#!div style="border: 1pt dotted; margin: 1em"
**wikipage** is another predefined class that will
be used when no class is specified.
}}}

{{{#!div class="compact" style="border: 1pt dotted; margin: 1em"
**compact** is another predefined class reducing
the padding within the `<div>` to a minimum.
}}}

{{{#!div class="wikipage compact" style="border: 1pt dotted"
Classes can be combined (here **wikipage** and **compact**)
which results in this case in reduced //vertical//
padding but there's still some horizontal space for coping
with headings.
}}}

{{{#!div class="" style="border: 1pt dotted; margin: 1em"
Explicitly specifying no classes is //not// the same
as specifying no class attribute, as this will remove
the //wikipage// default class.
}}}

important is a predefined class.

wikipage is another predefined class that will
be used when no class is specified.

compact is another predefined class reducing
the padding within the <div> to a minimum.

Classes can be combined (here wikipage and compact)
which results in this case in reduced vertical
padding but there's still some horizontal space for coping
with headings.

Explicitly specifying no classes is not the same
as specifying no class attribute, as this will remove
the wikipage default class.

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 site/style.css.

How to use #!td and other table related processors

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.

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.