Trac Macros

<ol><li><a href="#TracMacros">Trac Macros</a><ol><li><a href="#UsingMacros">Using Macros</a><ol><li><a href="#Example">Example</a></li></ol></li><li> <a href="#AvailableMacros">Available Macros</a></li><li> <a href="#Macrosfromaroundtheworld">Macros from around the world</a></li><li> <a href="#DevelopingCustomMacros">Developing Custom Macros</a></li><li> <a href="#Implementation">Implementation</a><ol><li><a href="#Macrowithoutarguments">Macro without arguments</a></li><li> <a href="#Macrowitharguments">Macro with arguments</a></li><li> <a href="#expand_macrodetails"><tt>expand_macro</tt> details</a></li></ol></li></ol></li></ol>

Trac macros are plugins to extend the Trac engine with custom 'functions' written in Python. A macro inserts dynamic HTML data in any context supporting WikiFormatting.

Another kind of macros are WikiProcessors. They typically deal with alternate markup formats and representation of larger blocks of information (like source code highlighting).

Using Macros

Macro calls are enclosed in two square brackets. Like Python functions, macros can also have arguments, a comma separated list within parentheses.

Trac macros can also be written as TracPlugins. This gives them some capabilities that macros do not have, such as being able to directly access the HTTP request.

Example

A list of 3 most recently changed wiki pages starting with 'Trac':

 [[RecentChanges(Trac,3)]]

Display:

07/22/11

06/23/09

Available Macros

Note that the following list will only contain the macro documentation if you've not enabled -OO optimizations, or not set the PythonOptimize option for mod_python.

[[InterTrac]]
<p> Provide a list of known <a class="wiki" href="/seiscomp3/InterTrac.html">InterTrac</a> prefixes. </p>
[[TitleIndex]]
<p> Inserts an alphabetic list of all wiki pages into the output. </p> <p> Accepts a prefix string as parameter: if provided, only pages with names that start with the prefix are included in the resulting list. If this parameter is omitted, all pages are listed. </p> <p> Alternate <tt>format</tt> and <tt>depth</tt> can be specified: </p> <ul><li><tt>format=group</tt>: The list of page will be structured in groups according to common prefix. This format also supports a <tt>min=n</tt> argument, where <tt>n</tt> is the minimal number of pages for a group. </li><li><tt>depth=n</tt>: limit the depth of the pages to list. If set to 0, only toplevel pages will be shown, if set to 1, only immediate children pages will be shown, etc. If not set, or set to -1, all pages in the hierarchy will be shown. </li></ul>
[[RecentChanges]]
<p> Lists all pages that have recently been modified, grouping them by the day they were last modified. </p> <p> This macro accepts two parameters. The first is a prefix string: if provided, only pages with names that start with the prefix are included in the resulting list. If this parameter is omitted, all pages are listed. </p> <p> The second parameter is a number for limiting the number of pages returned. For example, specifying a limit of 5 will result in only the five most recently changed pages to be included in the list. </p>
[[PageOutline]]
<p> Displays a structural outline of the current wiki page, each item in the outline being a link to the corresponding heading. </p> <p> This macro accepts three optional parameters: </p> <ul><li>The first is a number or range that allows configuring the minimum and maximum level of headings that should be included in the outline. For example, specifying "1" here will result in only the top-level headings being included in the outline. Specifying "2-3" will make the outline include all headings of level 2 and 3, as a nested list. The default is to include all heading levels. </li><li>The second parameter can be used to specify a custom title (the default is no title). </li><li>The third parameter selects the style of the outline. This can be either <tt>inline</tt> or <tt>pullout</tt> (the latter being the default). The <tt>inline</tt> style renders the outline as normal part of the content, while <tt>pullout</tt> causes the outline to be rendered in a box that is by default floated to the right side of the other content. </li></ul>
[[Image]]
<p> Embed an image in wiki-formatted text. </p> <p> The first argument is the file specification. The file specification may reference attachments in three ways: </p> <ul><li><tt>module:id:file</tt>, where module can be either <strong>wiki</strong> or <strong>ticket</strong>, to refer to the attachment named <i>file</i> of the specified wiki page or ticket. </li><li><tt>id:file</tt>: same as above, but id is either a ticket shorthand or a Wiki page name. </li><li><tt>file</tt> to refer to a local attachment named 'file'. This only works from within that wiki page or a ticket. </li></ul><p> Also, the file specification may refer to repository files, using the <tt>source:file</tt> syntax (<tt>source:file@rev</tt> works also). </p> <p> Files can also be accessed with a direct URLs; <tt>/file</tt> for a project-relative, <tt>//file</tt> for a server-relative, or <tt>http://server/file</tt> for absolute location of the file. </p> <p> The remaining arguments are optional and allow configuring the attributes and style of the rendered <tt>&lt;img&gt;</tt> element: </p> <ul><li>digits and unit are interpreted as the size (ex. 120, 25%) for the image </li><li><tt>right</tt>, <tt>left</tt>, <tt>top</tt> or <tt>bottom</tt> are interpreted as the alignment for the image </li><li><tt>link=some TracLinks...</tt> replaces the link to the image source by the one specified using a <a class="wiki" href="/seiscomp3/TracLinks.html">TracLinks</a>. If no value is specified, the link is simply removed. </li><li><tt>nolink</tt> means without link to image source (deprecated, use <tt>link=</tt>) </li><li><tt>key=value</tt> style are interpreted as HTML attributes or CSS style indications for the image. Valid keys are: <ul><li>align, border, width, height, alt, title, longdesc, class, id and usemap </li><li><tt>border</tt> can only be a number </li></ul></li></ul><p> Examples: </p> <pre class="wiki"> [[Image(photo.jpg)]] # simplest [[Image(photo.jpg, 120px)]] # with image width size [[Image(photo.jpg, right)]] # aligned by keyword [[Image(photo.jpg, nolink)]] # without link to source [[Image(photo.jpg, align=right)]] # aligned by attribute </pre><p> You can use image from other page, other ticket or other module. </p> <pre class="wiki"> [[Image(OtherPage:foo.bmp)]] # if current module is wiki [[Image(base/sub:bar.bmp)]] # from hierarchical wiki page [[Image(#3:baz.bmp)]] # if in a ticket, point to #3 [[Image(ticket:36:boo.jpg)]] [[Image(source:/images/bee.jpg)]] # straight from the repository! [[Image(htdocs:foo/bar.png)]] # image file in project htdocs dir. </pre><p> <i>Adapted from the Image.py macro created by Shun-ichi Goto &lt;<a class="mail-link" href="mailto:gotoh@taiyo.co.jp"><span class="icon"> </span>gotoh@taiyo.co.jp</a>&gt;</i> </p>
[[MacroList]]
<p> Displays a list of all installed Wiki macros, including documentation if available. </p> <p> Optionally, the name of a specific macro can be provided as an argument. In that case, only the documentation for that macro will be rendered. </p> <p> Note that this macro will not be able to display the documentation of macros if the <tt>PythonOptimize</tt> option is enabled for mod_python! </p>
[[TracIni]]
<p> Produce documentation for Trac configuration file. </p> <p> Typically, this will be used in the <a class="wiki" href="/seiscomp3/TracIni.html">TracIni</a> page. Optional arguments are a configuration section filter, and a configuration option name filter: only the configuration options whose section and name start with the filters are output. </p>
[[TracGuideToc]]
<p> This macro shows a quick and dirty way to make a table-of-contents for a set of wiki pages. </p>
[[TicketQuery]]
<p> Macro that lists tickets that match certain criteria. </p> <p> This macro accepts a comma-separated list of keyed parameters, in the form "key=value". </p> <p> If the key is the name of a field, the value must use the syntax of a filter specifier as defined in <a class="wiki" href="/seiscomp3/TracQuery.html#QueryLanguage">TracQuery#QueryLanguage</a>. Note that this is <i>not</i> the same as the simplified URL syntax used for <tt>query:</tt> links starting with a <tt>?</tt> character. </p> <p> In addition to filters, several other named parameters can be used to control how the results are presented. All of them are optional. </p> <p> The <tt>format</tt> parameter determines how the list of tickets is presented: </p> <ul><li><strong>list</strong> -- the default presentation is to list the ticket ID next to the summary, with each ticket on a separate line. </li><li><strong>compact</strong> -- the tickets are presented as a comma-separated list of ticket IDs. </li><li><strong>count</strong> -- only the count of matching tickets is displayed </li><li><strong>table</strong> -- a view similar to the custom query view (but without the controls) </li></ul><p> The <tt>max</tt> parameter can be used to limit the number of tickets shown (defaults to <strong>0</strong>, i.e. no maximum). </p> <p> The <tt>order</tt> parameter sets the field used for ordering tickets (defaults to <strong>id</strong>). </p> <p> The <tt>desc</tt> parameter indicates whether the order of the tickets should be reversed (defaults to <strong>false</strong>). </p> <p> The <tt>group</tt> parameter sets the field used for grouping tickets (defaults to not being set). </p> <p> The <tt>groupdesc</tt> parameter indicates whether the natural display order of the groups should be reversed (defaults to <strong>false</strong>). </p> <p> The <tt>verbose</tt> parameter can be set to a true value in order to get the description for the listed tickets. For <strong>table</strong> format only. <i>deprecated in favor of the <tt>rows</tt> parameter</i> </p> <p> The <tt>rows</tt> parameter can be used to specify which field(s) should be viewed as a row, e.g. <tt>rows=description|summary</tt> </p> <p> For compatibility with Trac 0.10, if there's a second positional parameter given to the macro, it will be used to specify the <tt>format</tt>. Also, using "&amp;" as a field separator still works (except for <tt>order</tt>) but is deprecated. </p>
[[InterWiki]]
<p> Provide a description list for the known <a class="wiki" href="/seiscomp3/InterWiki.html">InterWiki</a> prefixes. </p>
[[TracAdminHelp]]
<p> Displays help for trac-admin commands. </p> <p> Examples: </p> <pre class="wiki">[[TracAdminHelp]] # all commands [[TracAdminHelp(wiki)]] # all wiki commands [[TracAdminHelp(wiki export)]] # the "wiki export" command [[TracAdminHelp(upgrade)]] # the upgrade command </pre>
[[NewsFlash]]
<p> Makes a colored box from the contents of the macro. </p>
[[NewsFlashStart]]
<p> Start a newflash box. </p>
[[NewsFlashEnd]]
<p> End a newflash box. </p>
[[BlogList]]
<p> A macro to display list of posts and extracts outside (or inside) the Blog module - most commonly Wiki pages. </p> <p> All arguments are optional: </p> <pre class="wiki">[[BlogList]] </pre><p> Available named arguments: </p> <ul><li><tt>recent=</tt> - max. number of posts </li><li><tt>category=</tt> - a category </li><li><tt>author=</tt> - an author </li><li><tt>period=</tt> - time period of the format YYYY/MM </li><li><tt>heading=</tt> - a heading for the list </li><li><tt>format=</tt> - type of display (see below for details) </li><li><tt>max_size=</tt> - max. number of characters to render for each post </li></ul><p> Example showing some available named arguments: </p> <pre class="wiki">[[BlogList(recent=5, max_size=250, period=2007/12, author=osimons, format=float, heading=Some Trac Posts)]] </pre><p> The arguments for criteria are 'AND'-based, so the above example will render at most 5 posts by 'osimons' in December 2007. </p> <p> There is no heading unless specified. </p> <p> Without restriction on recent number of posts, it will use the number currently active in the Blog module as default for 'float' and 'full' rendering, but for rendering of 'inline' list it will render all found as default unless restricted. Additionally for 'float' and 'full' it will truncate content if it is larger than a max_size (if set). </p> <p> The <tt>format=</tt> keyword argument supports rendering these formats: </p> <table class="wiki"> <tr><td><tt>format=inline</tt></td><td>Renders an unordered list in the normal text flow (default). </td></tr><tr><td><tt>format=float</tt></td><td>A floating box out on the side of the page with slightly more detail. </td></tr><tr><td><tt>format=full</tt></td><td>Full rendering like on period, category and author listings inside blog. </td></tr></table> <p> The arguments can appear in any order. </p> <p> Posts are rendered sorted by newest first for all modes. </p>
[[Include]]
<p> Inserts the contents of another wiki page. It expands arguments in the page in the form {{N}}. </p> <p> Example: </p><div class="newsflash">&lt;h1 id="NewSeisComP3forum"&gt;New SeisComP3 forum&lt;/h1&gt; &lt;p&gt; &lt;a href="https://forum.seiscomp3.org"&gt;SC3 Forum&lt;/a&gt; has been launched to replace the mailing list. Please register to read software support categories. &lt;/p&gt; &lt;h1 id="NewSeisComP3Jakartarelease"&gt;New SeisComP3 Jakarta release&lt;/h1&gt; &lt;p&gt; The new release Jakarta 2016.333 is here. Please check the &lt;a href="https://github.com/SeisComP3/seiscomp3/blob/build/jakarta/2016.333/CHANGELOG.md"&gt;changelog&lt;/a&gt; for further information. &lt;a class="wiki" href="/seiscomp3/download.html"&gt;Download&lt;/a&gt;&lt;br /&gt; &lt;/p&gt; &lt;h1 id="SeisComP3onGithub"&gt;SeisComP3 on Github&lt;/h1&gt; &lt;p&gt; SeisComP3 source code is now available on &lt;a href="https://www.github.com/SeisComP3/seiscomp3"&gt;Github&lt;/a&gt;. &lt;/p&gt; &lt;h1 id="Tryarclink_fetch"&gt;Try arclink_fetch!&lt;/h1&gt; &lt;p&gt; The &lt;a class="wiki" href="/seiscomp3/doc/applications/arclink_fetch.html"&gt;arclink_fetch&lt;/a&gt; client is a convenient way to request data from an &lt;a class="wiki" href="/seiscomp3/doc/applications/arclink.html"&gt;ArcLink&lt;/a&gt; server such as the one included in SeisComP. &lt;a class="wiki" href="/seiscomp3/doc/applications/arclink_fetch.html"&gt;More information&lt;/a&gt;. &lt;/p&gt; &lt;h1 id="Ticketsystemavailable"&gt;Ticket system available&lt;/h1&gt; &lt;p&gt; Users are encouraged to create tickets for bugs and feature requests. This is a good chance to contribute to the development and the stability of SeisComP. Request a login to &lt;a href="/seiscomp3"&gt;http://www.seiscomp3.org&lt;/a&gt; by sending e-mail to &lt;a class="mail-link" href="mailto:geofon@gfz-potsdam.de"&gt;&lt;span class="icon"&gt;�&lt;/span&gt;geofon@gfz-potsdam.de&lt;/a&gt;. &lt;/p&gt; </div><h1 id="WelcometotheprojectsiteofSeisComP3">Welcome to the project site of SeisComP3</h1> <p> This page is the entry point if you want to learn about the SeisComP software, browse the documentation and inform yourself about the SeisComP license conditions. </p> <p> SeisComP is a seismological software for data acquisition, processing, distribution and interactive analysis that has been developed by the <a href="http://geofon.gfz-potsdam.de">GEOFON Program</a> at <a href="http://www.gfz-potsdam.de">Helmholtz Centre Potsdam, GFZ German Research Centre for Geosciences</a> and <a href="http://www.gempa.de">gempa GmbH</a>. </p> <h2 id="TableofContents">Table of Contents</h2> <ul><li><a class="wiki" href="/seiscomp3/about.html">About</a> </li><li><a class="wiki" href="/seiscomp3/license.html">License</a> </li><li><a class="wiki" href="/seiscomp3/doc.html">Documentation</a> </li><li><a class="wiki" href="/seiscomp3/doc/changelog.html">Changelog</a> </li><li><a class="wiki" href="/seiscomp3/community.html">Community</a> <ul><li><a class="wiki" href="/seiscomp3/contribs.html">Contributions</a> </li><li><a class="wiki" href="/seiscomp3/FAQ.html">Frequently Asked Questions</a> </li><li><a class="wiki" href="/seiscomp3/recipes.html">Recipes</a> </li><li><a class="wiki" href="/seiscomp3/dev.html">Development</a> </li><li><del><a class="wiki" href="/seiscomp3/wish-list.html">Wish list of new features</a></del>: Please use <del>the <a href="/seiscomp3/report">ticket system</a></del> <a href="https://github.com/SeisComP3/seiscomp3/issues">Github</a> instead. </li></ul></li><li><a class="wiki" href="/seiscomp3/support.html">Support</a> </li><li><a class="wiki" href="/seiscomp3/download.html">Download</a> </li><li><a class="wiki" href="/seiscomp3/contact.html">Contact</a> </li></ul><p> </p> <p> WARNING: avoid recursive inclusion. </p>
[[LatexDummy]]
<p> Macro with no effect </p>
[[LatexBeginDoc]]
<p> HTML version for <a class="missing wiki">TexLatexBeginDocMacro?</a> </p>
[[LatexEndDoc]]
<p> HTML version for <a class="missing wiki">TexLatexEndDocMacro?</a> </p>
[[LatexDocCls]]
<p> HTML version for <a class="missing wiki">TexLatexDocClsMacro?</a> </p>
[[LatexGetRes]]
<p> HTML version for <a class="missing wiki">TexLatexGetResMacro?</a> </p>
[[LatexCmd]]
<p> HTML version for <a class="missing wiki">TexLatexCmdMacro?</a> </p>
[[LatexUsePkg]]
<p> HTML version for <a class="missing wiki">TexLatexUsePkgMacro?</a> </p>
[[LatexTable]]
<p> HTML version for <a class="missing wiki">TexLatexTableMacro?</a> </p>
[[LatexLongTable]]
<p> HTML version for <a class="missing wiki">TexLatexLongTableMacro?</a> </p>
[[LatexBasicHeaders]]
<p> HTML version for <a class="missing wiki">TexLatexBasicHeadersMacro?</a> </p>
[[LatexSpecialChar]]
<p> HTML version for <a class="missing wiki">TexLatexSpecialCharMacro?</a> </p>
[[TexTracIni]]
<p> Not supported yet or not useful in Latex enviroment. </p>
[[TexTracAdminHelp]]
<p> Not supported yet or not useful in Latex enviroment. </p>
[[TexTitleIndex]]
<p> Not supported yet or not useful in Latex enviroment. </p>
[[TexTicketQuery]]
<p> Not supported yet or not useful in Latex enviroment. </p>
[[TexRecentChanges]]
<p> Not supported yet or not useful in Latex enviroment. </p>
[[TexPageOutline]]
<p> Not supported yet or not useful in Latex enviroment. </p>
[[TexMacroList]]
<p> Not supported yet or not useful in Latex enviroment. </p>
[[TexInterTrac]]
<p> Not supported yet or not useful in Latex enviroment. </p>
[[TexHelloWorld]]
<p> Not supported yet or not useful in Latex enviroment. </p>
[[TexTracGuideToc]]
<p> Not supported yet or not useful in Latex enviroment. </p>
[[TexLatexRender]]
<p> Not supported yet or not useful in Latex enviroment. </p>
[[Latex]]
<p> Latex <a class="missing wiki">WikiProcessor?</a>: Now you can specify small pieces of latex code into any wiki context, like <a class="wiki" href="/seiscomp3/WikiHtml.html">WikiHtml</a>. </p> <p> Ex.: </p> <pre class="wiki"> {{{ #!Latex %label=fig_math %width=800 %height=600 %dpi=300 %use=package[opts]:package_url $\frac{\alpha^{\beta^2}}{\delta + \alpha}$ }}} </pre><p> This code will produce a PNG file and a PDF file, both will be added to Attachments section. </p> <p> The parameters are specified as latex comments. </p> <p> %label Picture label, default value is 'unnamed', if two differents blocks has the same label, just the last block will be rendered. </p> <p> %width PNG and display width. </p> <p> %height PNG and display height. </p> <p> %dpi Dots per Inch (resolution), default value is 300. </p>
[[LatexRender]]
<p> Like Latex <a class="missing wiki">WikiProcessor?</a> <a class="missing wiki">LatexRender?</a> macro is used to specify small pieces of latex code into any wiki context, but <a class="missing wiki">LatexRender?</a> support latex code specified in other files (svn, attachments) and support external dependecies. </p> <p> Ex.: </p> <pre class="wiki">[[LatexRender(source:/docs/tex/math.tex,inc=mymacros.sty,inc=others.sty,width=800,height=600,dpi=300)]] </pre><p> This example will produce the same two figures as <a class="missing wiki">LatexMacro?</a> using the tex file /docs/tex/math.tex in SVN with two external dependencies (\usepackage) in Attachments section. </p> <p> The first parameter must be a URL to source code. The parameter "inc" is used to specify the external dependency URL and the others parameters are the same as <a class="missing wiki">LatexMacro?</a> </p> <p> width height dpi </p> <p> You can use the parameter "code" to specify a latex source code. </p> <p> Ex.: </p> <pre class="wiki">[[LatexRender(code="$\frac{\alpha}{\beta}$",inc=mymacros.sty,inc=others.sty,width=800,height=600,dpi=300)]] </pre>
[[TexImage]]
<p> This is the Tex version of Image macro. </p>
[[TexLatexBasicHeaders]]
<p> Include some necessary packages and macros to render latex documents. </p>
[[TexLatexBeginDoc]]
<p> This inform to Trac2Latex parser where the document begins. </p>
[[TexLatexCmd]]
<p> This macro inform to Trac2Latex parser a latex command to be inserted. </p> <p> Ex.: </p> <pre class="wiki">[[LatexCmd("\maketitle")]] </pre>
[[TexLatexDocCls]]
<p> This macro inform to Trac2Latex parser the document class and parameters. </p> <p> Ex.: </p> <pre class="wiki">[[LatexDocClsMacro(atricle,a4paper)]] </pre>
[[TexLatexEndDoc]]
<p> This inform to Trac2Latex parser where the document ends. </p>
[[TexLatexGetRes]]
<p> This macro inform to Trac2Latex parser a external dependency URL. This dependency (picture, package, document class, etc...) will be downloaded to a temporary directory. </p> <p> Ex.: </p> <pre class="wiki">[[LatexGetRes(source:/docs/math.tex)]] </pre>
[[TexLatex]]
<p> Tex version to Latex <a class="missing wiki">WikiProcessor?</a>, does nothing, just return the latex code. </p>
[[TexLatexSpecialChar]]
<p> Return Tex version for some special characters, like %, $, alpha, beta, etc... </p>
[[TexLatexTable]]
<p> Include all necessary packages and macros to render latex tables. </p>
[[TexLatexLongTable]]
<p> Include all necessary packages and macros to render latex tables. </p>
[[TexLatexUsePkg]]
<p> This macro inform to Trac2Latex parser a package to be used (\usepackage). </p> <p> Ex.: </p> <pre class="wiki">[[LatexUsePkg(tabular)]] </pre>
[[TexTimestamp]]
<p> Tex version to Timestamp macro. Return \today. </p>
[[TexInclude]]
<p> This is the Tex version of Image macro. </p>

Macros from around the world

The Trac Hacks site provides a wide collection of macros and other Trac plugins contributed by the Trac community. If you're looking for new macros, or have written one that you'd like to share with the world, please don't hesitate to visit that site.

Developing Custom Macros

Macros, like Trac itself, are written in the Python programming language.

For more information about developing macros, see the development resources on the main project site.

Implementation

Here are 2 simple examples showing how to create a Macro with Trac 0.11.

Also, have a look at Timestamp.py for an example that shows the difference between old style and new style macros and at the macros/README which provides a little more insight about the transition.

Macro without arguments

It should be saved as TimeStamp.py as Trac will use the module name as the Macro name

from datetime import datetime
# Note: since Trac 0.11, datetime objects are used internally

from genshi.builder import tag

from trac.util.datefmt import format_datetime, utc
from trac.wiki.macros import WikiMacroBase

class TimeStampMacro(WikiMacroBase):
    """Inserts the current time (in seconds) into the wiki page."""

    revision = "$Rev$"
    url = "$URL$"

    def expand_macro(self, formatter, name, args):
        t = datetime.now(utc)
        return tag.b(format_datetime(t, '%c'))

Macro with arguments

It should be saved as HelloWorld.py (in the plugins/ directory) as Trac will use the module name as the Macro name

from trac.wiki.macros import WikiMacroBase

class HelloWorldMacro(WikiMacroBase):
    """Simple HelloWorld macro.

    Note that the name of the class is meaningful:
     - it must end with "Macro"
     - what comes before "Macro" ends up being the macro name

    The documentation of the class (i.e. what you're reading)
    will become the documentation of the macro, as shown by
    the !MacroList macro (usually used in the WikiMacros page).
    """

    revision = "$Rev$"
    url = "$URL$"

    def expand_macro(self, formatter, name, args):
        """Return some output that will be displayed in the Wiki content.

        `name` is the actual name of the macro (no surprise, here it'll be
        `'HelloWorld'`),
        `args` is the text enclosed in parenthesis at the call of the macro.
          Note that if there are ''no'' parenthesis (like in, e.g.
          [[HelloWorld]]), then `args` is `None`.
        """
        return 'Hello World, args = ' + unicode(args)
    
    # Note that there's no need to HTML escape the returned data,
    # as the template engine (Genshi) will do it for us.

expand_macro details

expand_macro should return either a simple Python string which will be interpreted as HTML, or preferably a Markup object (use from trac.util.html import Markup). Markup(string) just annotates the string so the renderer will render the HTML string as-is with no escaping. You will also need to import Formatter using from trac.wiki import Formatter.

If your macro creates wiki markup instead of HTML, you can convert it to HTML like this:

  text = "whatever wiki markup you want, even containing other macros"
  # Convert Wiki markup to HTML, new style
  out = StringIO()
  Formatter(self.env, formatter.context).format(text, out)
  return Markup(out.getvalue())