code: def _handle_ansi_color_codes(self, s):
      
      parts = HtmlReporter._ANSI_COLOR_CODE_RE.split(s)
      ret = []
      span_depth = 0
      # Note that len(parts) is always odd: text, code, text, code, ..., text.
      for i in range(0, len(parts), 2):
        ret.append(parts[i])
        if i + 1 < len(parts):
          for code in parts[i + 1].split(';'):
            if code == 0:  # Reset.
              while span_depth > 0:
                ret.append('</span>')
                span_depth -= 1
            else:
              ret.append('<span class="ansi-{}">'.format(code))
              span_depth += 1
      while span_depth > 0:
        ret.append('</span>')
        span_depth -= 1
  
      return ''.join(ret)
docs: Replace ansi escape sequences with spans of appropriately named css classes.