docs: def main():
      """Filters the document AST."""
  
      # pylint: disable=global-statement
      global PANDOCVERSION
      global AttrMath
  
      # Get the output format and document
      fmt = args.fmt
      doc = json.loads(STDIN.read())
  
      # Initialize pandocxnos
      # pylint: disable=too-many-function-args
      PANDOCVERSION = pandocxnos.init(args.pandocversion, doc)
  
      # Element primitives
      AttrMath = elt('Math', 3)
  
      # Chop up the doc
      meta = doc['meta'] if PANDOCVERSION >= '1.18' else doc[0]['unMeta']
      blocks = doc['blocks'] if PANDOCVERSION >= '1.18' else doc[1:]
  
      # Process the metadata variables
      process(meta)
  
      # First pass
      attach_attrs_math = attach_attrs_factory(Math, allow_space=True)
      detach_attrs_math = detach_attrs_factory(Math)
      insert_secnos = insert_secnos_factory(Math)
      delete_secnos = delete_secnos_factory(Math)
      altered = functools.reduce(lambda x, action: walk(x, action, fmt, meta),
                                 [attach_attrs_math, insert_secnos,
                                  process_equations, delete_secnos,
                                  detach_attrs_math], blocks)
  
      # Second pass
      process_refs = process_refs_factory(references.keys())
      replace_refs = replace_refs_factory(references,
                                          use_cleveref_default, use_eqref,
                                          plusname if not capitalize else
                                          [name.title() for name in plusname],
                                          starname, 'equation')
      altered = functools.reduce(lambda x, action: walk(x, action, fmt, meta),
                                 [repair_refs, process_refs, replace_refs],
                                 altered)
  
      # Update the doc
      if PANDOCVERSION >= '1.18':
          doc['blocks'] = altered
      else:
          doc = doc[:1] + altered
  
      # Dump the results
      json.dump(doc, STDOUT)
  
      # Flush stdout
      STDOUT.flush()