docs: def convert_text(text,
                   input_format='markdown',
                   output_format='panflute',
                   standalone=False,
                   extra_args=None):
      """
      Convert formatted text (usually markdown) by calling Pandoc internally
  
      The default output format ('panflute') will return a tree
      of Pandoc elements. When combined with 'standalone=True', the tree root
      will be a 'Doc' element.
  
      Example:
  
          >>> from panflute import *
          >>> md = 'Some *markdown* **text** ~xyz~'
          >>> tex = r'Some $x^y$ or $x_n = \sqrt{a + b}$ \textit{a}'
          >>> convert_text(md)
          [Para(Str(Some) Space Emph(Str(markdown)) Space Strong(Str(text)) Space Subscript(Str(xyz)))]
          >>> convert_text(tex)
          [Para(Str(Some) Space Math(x^y; format='InlineMath') Space Str(or) Space Math(x_n = \sqrt{a + b}; format='InlineMath') Space RawInline(\textit{a}; format='tex'))]
  
  
      :param text: text that will be converted
      :type text: :class:`str` | :class:`.Element` | :class:`list` of :class:`.Element`
      :param input_format: format of the text (default 'markdown').
       Any Pandoc input format is valid, plus 'panflute' (a tree of Pandoc
       elements)
      :param output_format: format of the output
       (default is 'panflute' which creates the tree of Pandoc elements).
       Non-binary Pandoc formats are allowed (e.g. markdown, latex is allowed,
       but docx and pdf are not).
      :param standalone: whether the results will be a standalone document
       or not.
      :type standalone: :class:`bool`
      :param extra_args: extra arguments passed to Pandoc
      :type extra_args: :class:`list`
      :rtype: :class:`list` | :class:`.Doc` | :class:`str`
  
      Note: for a more general solution,
      see `pyandoc <https://github.com/kennethreitz/pyandoc/>`_
      by Kenneth Reitz.
      """
  
      if input_format == 'panflute':
  
          # Problem:
          #  We need a Doc element, but received a list of elements.
          #  So we wrap-up the list in a Doc, but with what pandoc-api version?
          #  (remember that Pandoc requires a matching api-version!)
          # Workaround: call Pandoc with empty text to get its api-version
          if not isinstance(text, Doc):
              tmp_doc = convert_text('', standalone=True)
              api_version = tmp_doc.api_version
              if isinstance(text, Element):
                  text = [text]
              text = Doc(*text, api_version=api_version)
  
          # Dump the Doc into json
          with io.StringIO() as f:
              dump(text, f)
              text = f.getvalue()
  
      in_fmt = 'json' if input_format == 'panflute' else input_format
      out_fmt = 'json' if output_format == 'panflute' else output_format
  
      if extra_args is None:
          extra_args = []
  
      if standalone:
          extra_args.append('--standalone')
  
      out = inner_convert_text(text, in_fmt, out_fmt, extra_args)
  
      if output_format == 'panflute':
          out = json.loads(out, object_pairs_hook=from_json)
  
          if standalone:
              if not isinstance(out, Doc):  # Pandoc 1.7.2 and earlier
                  metadata, items = out
                  out = Doc(*items, metadata=metadata)
          else:
              if isinstance(out, Doc):  # Pandoc 1.8 and later
                  out = out.content.list
              else:
                  out = out[1]  # Pandoc 1.7.2 and earlier
  
      return out