code: def tidyHTML(dirtyHTML):
      
      try:
          from tidylib import tidy_document
      except ImportError as e:
          raise ImportError(("%s\nYou need to install pytidylib.\n" +
               "e.g. sudo pip install pytidylib") % e)
      options = {
          'output-xhtml':1,
          #add_xml_decl=1,#option in tidy but not pytidylib
          'indent':1,
          'tidy-mark':1,
          #'char-encoding':'utf8',
          'char-encoding':'raw',
      }
      html, errors = tidy_document(dirtyHTML, options=options)
      return html
docs: Runs an arbitrary HTML string through Tidy.