docs: def load(input_stream=None):
      """
      Load JSON-encoded document and return a :class:`.Doc` element.
  
      The JSON input will be read from :data:`sys.stdin` unless an alternative
      text stream is given (a file handle).
  
      To load from a file, you can do:
  
          >>> import panflute as pf
          >>> with open('some-document.json', encoding='utf-8') as f:
          >>>     doc = pf.load(f)
  
      To load from a string, you can do:
  
          >>> import io
          >>> raw = '[{"unMeta":{}},
          [{"t":"Para","c":[{"t":"Str","c":"Hello!"}]}]]'
          >>> f = io.StringIO(raw)
          >>> doc = pf.load(f)
  
      :param input_stream: text stream used as input
          (default is :data:`sys.stdin`)
      :rtype: :class:`.Doc`
      """
  
      if input_stream is None:
          input_stream = io.open(sys.stdin.fileno()) if py2 else io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
  
      # Load JSON and validate it
      doc = json.load(input_stream, object_pairs_hook=from_json)
  
      # Notes:
      # - We use 'object_pairs_hook' instead of 'object_hook' to preserve the
      #   order of the metadata.
      # - The hook gets called for dicts (not lists), and the deepest dicts
      #   get called first (so you can ensure that when you receive a dict,
      #   its contents have already been fed to the hook).
  
      # Compatibility:
      # - Before Pandoc 1.8 (1.7 or earlier, AKA "Pandoc Legacy"),
      #   the JSON is a list:
      #   [{"unMeta":{META}},[BLOCKS]]
      # - Afterwards, it's a dict:
      #   {"pandoc-api-version" : [MAJ, MIN, REV],
      #    "meta" : META, "blocks": BLOCKS}
      # - This means that on legacy, the hook WILL NOT get called on the entire
      #   document and we need to create the Doc() element by hand
  
      # Corner cases:
      # - If META is missing, 'object_pairs_hook' will receive an empty list
  
      # Output format
      format = sys.argv[1] if len(sys.argv) > 1 else 'html'
  
      # API Version
      if isinstance(doc, Doc):
          # Modern Pandoc
          doc.format = format
          pass
      else:
          # Legacy Pandoc
          metadata, items = doc
          assert type(items) == list
          assert len(doc) == 2, 'json.load returned list with unexpected size:'
          doc = Doc(*items, metadata=metadata, format=format)
  
      return doc