| 1 | from trac.core import * |
|---|
| 2 | from trac.wiki.macros import WikiMacroBase |
|---|
| 3 | from StringIO import StringIO |
|---|
| 4 | |
|---|
| 5 | __all__ = ['ColorMacro'] |
|---|
| 6 | |
|---|
| 7 | class ColorMacro(WikiMacroBase): |
|---|
| 8 | """ |
|---|
| 9 | Macro for colorizing short text , usage is |
|---|
| 10 | |
|---|
| 11 | {{{ |
|---|
| 12 | [[Color(color, text)]] |
|---|
| 13 | }}} |
|---|
| 14 | |
|---|
| 15 | """ |
|---|
| 16 | def render_macro(self, formatter, name, args): |
|---|
| 17 | buf = StringIO() |
|---|
| 18 | if args: |
|---|
| 19 | args = args.split(', ',1) |
|---|
| 20 | buf.write("<font color='%(color)s'>%(text)s</font>" % dict(color=args[0], text=args[1])) |
|---|
| 21 | else: |
|---|
| 22 | buf.write("<p style='font-weight:bold; color:red;'>[[Color()]] macro requires a color spec and text: [[Color(color, text)]]</p>\n") |
|---|
| 23 | |
|---|
| 24 | return buf.getvalue() |
|---|