docs: def dehtml(text):
      '''Remove HTML tag in input text and format the texts
      accordingly. '''
      # added by BoPeng to handle html output from kernel
      #
      # Do not understand why, but I cannot define the class outside of the
      # function.
      try:
          # python 2
          from HTMLParser import HTMLParser
      except ImportError:
          # python 3
          from html.parser import HTMLParser
      # added by BoPeng to handle html output from kernel
      class _DeHTMLParser(HTMLParser):
          '''This parser analyzes input text, removes HTML tags such as
          <p>, <br>, <ul>, <li> etc and returns properly formatted texts.
          '''
          def __init__(self):
              HTMLParser.__init__(self)
              self.__text = []
  
          def handle_data(self, data):
              text = data.strip()
              if len(text) > 0:
                  text = re.sub('[ \t\r\n]+', ' ', text)
                  self.__text.append(text + ' ')
  
          def handle_starttag(self, tag, attrs):
              if tag == 'p':
                  self.__text.append('\n\n\n\n')
              elif tag == 'br':
                  self.__text.append('\n\n')
              elif tag == 'ul':
                  self.__text.append('')
              elif tag == 'li':
                  self.__text.append('\n\n  * ')
  
          def handle_endtag(self, tag):
              if tag == 'ul':
                  self.__text.append('\n\n')
              if tag == 'li':
                  self.__text.append('\n\n')
  
          def handle_startendtag(self, tag, attrs):
              if tag == 'br':
                  self.__text.append('\n\n')
  
          def text(self):
              return ''.join(self.__text).strip()
  
      try:
          parser = _DeHTMLParser()
          parser.feed(text)
          parser.close()
          return parser.text()
      except Exception as e:
          return text