code: def toctree_check(app: Sphinx, doctree: nodes.document, docname: str):
      whitelist = app.config.toctree_check_whitelist
  
      if docname in whitelist:
          return
  
      # Scan top-level nodes
      has_toctree = False
  
      other_types = []
  
      for i in range(len(doctree[0])):
          node = doctree[0][i]
          if isinstance(_strip_compound(node), toctree):
              has_toctree = True
          elif isinstance(_strip_compound(node), nodes.title):
              # Allow title
              pass
          else:
              other_types.append(type(_strip_compound(node)))
  
      if has_toctree and other_types:
          # We don't allow a document with toctree to have other types of contents
          logger.warning(
              "Expect a toctree document to contain only a toctree, "
              "but found other types of contents: %s",
              str(set(other_types)),
              location=docname,
          )
  
file_path: nni/docs/extension/toctree_check.py
imports: import re
  from docutils import nodes
  from sphinx.application import Sphinx
  from sphinx.addnodes import toctree
  from sphinx.util.logging import getLogger
label_desc: Use image node_id 2 for calling a global function with example usage: toctree_check(app, doctree, docname) without return types