Project

General

Profile

« Previous | Next » 

Revision 2471

strings.py: Added as_code()

View differences:

strings.py
94 94
def strip_ctrl(str_):
95 95
    '''Strips (non-printable) control characters'''
96 96
    return ''.join(filter(lambda c: not is_ctrl(c), str_))
97

  
98
##### Formatting
99

  
100
def as_code(str_, lang=None):
101
    '''Wraps a string in Redmine tags to syntax-highlight it.'''
102
    str_ = '\n'+str_.rstrip()+'\n'
103
    if lang != None: str_ = '<code class="'+lang+'">'+str_+'</code>'
104
    return '<pre>'+str_+'</pre>'

Also available in: Unified diff