docs: def run_filters(actions,
                  prepare=None, finalize=None,
                  input_stream=None, output_stream=None,
                  doc=None,
                  **kwargs):
      """
      Receive a Pandoc document from the input stream (default is stdin),
      walk through it applying the functions in *actions* to each element,
      and write it back to the output stream (default is stdout).
  
      Notes:
  
      - It receives and writes the Pandoc documents as JSON--encoded strings;
        this is done through the :func:`.load` and :func:`.dump` functions.
      - It walks through the document once for every function in *actions*,
        so the actions are applied sequentially.
      - By default, it will read from stdin and write to stdout,
        but these can be modified.
      - It can also apply functions to the entire document at the beginning and
        end; this allows for global operations on the document.
      - If ``doc`` is a :class:`.Doc` instead of ``None``, ``run_filters``
        will return the document instead of writing it to the output stream.
  
      :param actions: sequence of functions; each function takes (element, doc)
       as argument, so a valid header would be ``def action(elem, doc):``
      :type actions: [:class:`function`]
      :param prepare: function executed at the beginning;
       right after the document is received and parsed
      :type prepare: :class:`function`
      :param finalize: function executed at the end;
       right before the document is converted back to JSON and written to stdout.
      :type finalize: :class:`function`
      :param input_stream: text stream used as input
          (default is :data:`sys.stdin`)
      :param output_stream: text stream used as output
          (default is :data:`sys.stdout`)
      :param doc: ``None`` unless running panflute as a filter, in which case this will be a :class:`.Doc` element
      :type doc: ``None`` | :class:`.Doc`
      :param \*kwargs: keyword arguments will be passed through to the *action*
       functions (so they can actually receive more than just two arguments
       (*element* and *doc*)
      """
  
      load_and_dump = (doc is None)
  
      if load_and_dump:
          doc = load(input_stream=input_stream)
  
      if prepare is not None:
          prepare(doc)
  
      for action in actions:
          if kwargs:
              action = partial(action, **kwargs)
          doc = doc.walk(action, doc)
  
      if finalize is not None:
          finalize(doc)
  
      if load_and_dump:
          dump(doc, output_stream=output_stream)
      else:
          return(doc)