| 1 | """Example macro.""" |
|---|
| 2 | from trac.core import * |
|---|
| 3 | from trac.wiki.macros import WikiMacroBase |
|---|
| 4 | from trac.util import escape |
|---|
| 5 | |
|---|
| 6 | __all__ = ['HelloWorldMacro'] |
|---|
| 7 | |
|---|
| 8 | class 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 | |
|---|