def render_bbcode(value): """ Generates (X)HTML from string with BBCode "markup". By using the postmark lib from: @see: http://code.google.com/p/postmarkup/ """ value = mark_safe(_render_bbcode(value).replace("[", "[").replace("]", "]")) return value
def render_bbcode(value, nbsp=False): """ Generates (X)HTML from string with BBCode "markup". By using the postmark lib from: @see: http://code.google.com/p/postmarkup/ """ value = _render_bbcode(value)\ .replace('&#91;', '[').replace('&#93;', ']') if nbsp: value = re.sub('(^|<[^/>][^>]+>)(\s+)', lambda r: r.group(1) + ' ' * len(r.group(2)), value) return mark_safe(value)