def plaintext2html(text, container_tag=False):
 text = cgi.escape(ustr(text))
 text = text.replace('\n', '<br/>')
 text = text.replace('\r', '<br/>')
 text = html_keep_url(text)
 idx = 0
 final = '<p>'
 br_tags = re.compile('(([<]\\s*[bB][rR]\\s*\\/?[>]\\s*){2,})')
 for item in re.finditer(br_tags, text):
  final += (text[idx:item.start()] + '</p><p>')
  idx = item.end()
 final += (text[idx:] + '</p>')
 if container_tag:
  final = ('<%s>%s</%s>' % (container_tag, final, container_tag))
 return ustr(final)

def plaintext2html ( text , container_tag = False ) : text = cgi . escape ( ustr ( text ) ) text = text . replace ( '\n' , '<br/>' ) text = text . replace ( '\r' , '<br/>' ) text = html_keep_url ( text ) idx = 0 final = '<p>' br_tags = re . compile ( '(([<]\\s*[bB][rR]\\s*\\/?[>]\\s*){2,})' ) for item in re . finditer ( br_tags , text ) : final += ( text [ idx : item . start ( ) ] + '</p><p>' ) idx = item . end ( ) final += ( text [ idx : ] + '</p>' ) if container_tag : final = ( '<%s>%s</%s>' % ( container_tag , final , container_tag ) ) return ustr ( final )
convert plaintext into html .