Version 2 (modified by trac, 9 years ago) (diff)

--

Using HTML in Wiki Text

Trac supports inserting HTML into any wiki context, accomplished using the HTML WikiProcessor.

HTML support is built-in, and does not require installing any additional packages.

How to Use HTML

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

This example should explain:

{{{
#!html
<h1 style="text-align: right; color: blue">HTML Test</h1>
}}}

Results in:

HTML Test

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.

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. The new way to wrap any wiki content inside a <div> is to use the div Wiki processor:

{{{
#!div class=important style="border: 2pt solid; text-align: center"
This is the ''only'' way to go in Trac 0.11
}}}

Results in:

This is the only way to go in Trac 0.11

Note that the contents of a #!div block are contained in one or more paragraphs, which have a non-zero top and bottom margin by default. 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.

For spans, you should rather use the Macro call syntax:

 Hello [[span(''WORLD'' (click [#world-anchor here]), style=color: green; font-size: 120%, id=world-anchor)]]!

Results in:

Hello WORLD (click here)!

HTML comments

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:

{{{
#!htmlcomment
This block is translated to an HTML comment.
It can contain <tags> and &entities; that will not be escaped in the output.
}}}

results in the following block in the HTML output:

<!--
This block is translated to an HTML comment.
It can contain <tags> and &entities; that will not be escaped in the output.
-->

Please note that the character sequence "--" is not allowed in HTML comments, and will generate a rendering error.

More Information


See also: WikiProcessors, WikiFormatting, WikiRestructuredText