code: def pisaParser(src, context, default_css="", xhtml=False, encoding=None, xml_output=None):
      
  
      global CSSAttrCache
      CSSAttrCache = {}
  
      if xhtml:
          # TODO: XHTMLParser doesn't see to exist...
          parser = html5lib.XHTMLParser(tree=treebuilders.getTreeBuilder("dom"))
      else:
          parser = html5lib.HTMLParser(tree=treebuilders.getTreeBuilder("dom"))
  
      if isinstance(src, six.text_type):
          # If an encoding was provided, do not change it.
          if not encoding:
              encoding = "utf-8"
          src = src.encode(encoding)
          src = pisaTempFile(src, capacity=context.capacity)
  
      # # Test for the restrictions of html5lib
      # if encoding:
      #     # Workaround for html5lib<0.11.1
      #     if hasattr(inputstream, "isValidEncoding"):
      #         if encoding.strip().lower() == "utf8":
      #             encoding = "utf-8"
      #         if not inputstream.isValidEncoding(encoding):
      #             log.error("%r is not a valid encoding e.g. 'utf8' is not valid but 'utf-8' is!", encoding)
      #     else:
      #         if inputstream.codecName(encoding) is None:
      #             log.error("%r is not a valid encoding", encoding)
      document = parser.parse(
          src,
      )  # encoding=encoding)
  
      if xml_output:
          if encoding:
              xml_output.write(document.toprettyxml(encoding=encoding))
          else:
              xml_output.write(document.toprettyxml(encoding="utf8"))
  
      if default_css:
          context.addDefaultCSS(default_css)
  
      pisaPreLoop(document, context)
      # try:
      context.parseCSS()
      # except:
      #    context.cssText = DEFAULT_CSS
      #    context.parseCSS()
      # context.debug(9, pprint.pformat(context.css))
  
      pisaLoop(document, context)
      return context
docs: - Parse HTML and get miniDOM
      - Extract CSS informations, add default CSS, parse CSS
      - Handle the document DOM itself and build reportlab story
      - Return Context object