Edgewall Software

ProcessorBazaar: LegendBox-0.10.py

File LegendBox-0.10.py, 1.2 kB (added by Lars Stavholm <stava@…>, 22 months ago)

LegendBox macro updated for Trac 0.10

Line 
1'''
2A wiki-processor for encapsulating wiki text inside a box.
3The box will have a legend and a modifiable color.
4
5Example:
6
7{{{
8#!LegendBox
9#!color: blue
10#!legend: My Title
11Here comes the actual text that comes inside the box.
12You can even use wiki-formatting in here.
13}}}
14
15You can modify the default COLOR, LEGEND and the STYLE in this plugin file.
16
17'''
18
19from trac.wiki import wiki_to_html, wiki_to_oneliner
20
21STYLE  = 'margin-top: 2px; color:black; background-color:%s; '\
22         'border: solid black 1px'
23COLOR  = 'white'
24LEGEND = 'Items'
25
26def execute(hdf, txt, env):
27    lines  = txt.split('\n')
28    color  = COLOR
29    legend = LEGEND
30    offset = 0
31    for l in lines[:2]:
32        if l.startswith('#!color'):
33            color = l.split(':',1)[-1]
34            offset += 1
35        elif l.startswith('#!legend'):
36            legend = l.split(':',1)[-1]
37            offset += 1
38   
39    return _build_field_set(hdf, '\n'.join(lines[offset:]), env, legend, color)
40
41def _build_field_set(hdf, txt, env, legend, color):
42    style = STYLE % color
43    html = '<fieldset style="%s"><legend style="%s">' \
44           '%s</legend>%s</fieldset>' % \
45          (style,style,wiki_to_oneliner(legend,env),wiki_to_html(txt,env,None))
46    return html