Edgewall Software

MacroBazaar: Color-0.11v2.py

File Color-0.11v2.py, 792 bytes (added by sebastian@…, 5 years ago)

Supports background-colour and padding like the original Color.py

Line 
1from trac.core import *
2from trac.wiki.macros import WikiMacroBase
3from StringIO import StringIO
4
5__all__ = ['ColorMacro']
6
7class 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()