| 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 | Rename into Color.py before installing. |
|---|
| 10 | |
|---|
| 11 | Macro for colorizing short text , usage is |
|---|
| 12 | |
|---|
| 13 | {{{ |
|---|
| 14 | [[Color(color, text)]] |
|---|
| 15 | }}} |
|---|
| 16 | |
|---|
| 17 | """ |
|---|
| 18 | def render_macro(self, formatter, name, args): |
|---|
| 19 | buf = StringIO() |
|---|
| 20 | if args: |
|---|
| 21 | args = tuple(args.split(",")) |
|---|
| 22 | if len(args) == 3: |
|---|
| 23 | buf.write('<span style="background-color:%s;padding: 0.1ex 0.4em;color:%s;">%s</span>' % args) |
|---|
| 24 | else: |
|---|
| 25 | buf.write('<span style="background-color:%s;padding: 0.1ex 0.4em;">%s</span>' % args) |
|---|
| 26 | else: |
|---|
| 27 | buf.write("<p style='font-weight:bold; color:red;'>[[Color()]] macro requires a color spec and text: [[Color(color, text)]]</p>\n") |
|---|
| 28 | |
|---|
| 29 | return buf.getvalue() |
|---|