Edgewall Software

Ticket #5274: HelloWorld.py

File HelloWorld.py, 623 bytes (added by dharris <dharris+trac@…>, 5 years ago)

HelloWorld? macro for use in 0.11 trac

Line 
1"""Example macro."""
2from trac.core import *
3from trac.wiki.macros import WikiMacroBase
4from trac.util import escape
5
6__all__ = ['HelloWorldMacro']
7
8class HelloWorldMacro(WikiMacroBase):
9        """
10        Demo macro for a greeting with an argument.
11
12        {{{
13        [[HelloWorld(args)]]
14        }}}
15
16        """
17        def expand_macro(self, formatter, name, args):
18                # args will be `None` if the macro is called without parenthesis.
19                txt = args or 'No arguments'
20
21                # then, as `txt` comes from the user, it's important to guard against
22                # the possibility to inject malicious HTML/Javascript, by using `escape()`:
23                return 'Hello World, args = ' + escape(txt)
24