code: def build_full_toctree(builder, docname, prune, collapse):
      """Return a single toctree starting from docname containing all
      sub-document doctrees.
      """
      env = builder.env
      doctree = env.get_doctree(env.config.master_doc)
      toctrees = []
      for toctreenode in doctree.traverse(addnodes.toctree):
          toctree = env.resolve_toctree(
              docname,
              builder,
              toctreenode,
              collapse=collapse,
              prune=prune,
              includehidden=True,
          )
          if toctree is not None:
              toctrees.append(toctree)
  
      if not toctrees:
          return None
      result = toctrees[0]
      for toctree in toctrees[1:]:
          if toctree:
              result.extend(toctree.children)
      env.resolve_references(result, docname, builder)
      return result
  
imports: from sphinx import addnodes
label_desc: Use image node_id 3 for calling a global function with example usage: build_full_toctree(builder, docname, prune, collapse) and returns: result, None