Revision 2477
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/strings.py | ||
---|---|---|
97 | 97 |
|
98 | 98 |
##### Formatting |
99 | 99 |
|
100 |
def as_tt(str_): return '@'+str_+'@' |
|
101 |
|
|
100 | 102 |
def as_code(str_, lang=None, multiline=True): |
101 | 103 |
'''Wraps a string in Redmine tags to syntax-highlight it.''' |
102 | 104 |
str_ = '\n'+str_.rstrip()+'\n' |
103 | 105 |
if lang != None: str_ = '<code class="'+lang+'">'+str_+'</code>' |
104 | 106 |
if multiline: str_ = '<pre>'+str_+'</pre>' |
105 | 107 |
return str_ |
108 |
|
|
109 |
def as_table(dict_, key_label='Output', value_label='Input'): |
|
110 |
'''Wraps a dict in Redmine tags to format it as a table.''' |
|
111 |
str_ = '' |
|
112 |
def row(entry): return ('|'.join(['']+entry+['']))+'\n'# '' for outer border |
|
113 |
str_ += row([key_label, value_label]) |
|
114 |
for entry in dict_.iteritems(): str_ += row([as_tt(ustr(v)) for v in entry]) |
|
115 |
return str_ |
Also available in: Unified diff
strings.py: Added as_tt() and as_table()