def to_html_string(text):
 if text:
  try:
   text = unicodify(text)
  except UnicodeDecodeError as e:
   return ('Error decoding string: %s' % str(e))
  text = text_type(markupsafe.escape(text))
  text = text.replace('\n', '<br/>')
  text = text.replace('    ', '&nbsp;&nbsp;&nbsp;&nbsp;')
  text = text.replace(' ', '&nbsp;')
 return text

def to_html_string ( text ) : if text : try : text = unicodify ( text ) except UnicodeDecodeError as e : return ( 'Error decoding string: %s' % str ( e ) ) text = text_type ( markupsafe . escape ( text ) ) text = text . replace ( '\n' , '<br/>' ) text = text . replace ( '    ' , '&nbsp;&nbsp;&nbsp;&nbsp;' ) text = text . replace ( ' ' , '&nbsp;' ) return text
translates the characters in text to an html string .