code: def inline_all_toctrees(
      builder: Builder,
      docnameset: set[str],
      docname: str,
      tree: nodes.document,
      colorfunc: Callable,
      traversed: list[str],
  ) -> nodes.document:
      """Inline all toctrees in the *tree*.
  
      Record all docnames in *docnameset*, and output docnames with *colorfunc*.
      """
      tree = tree.deepcopy()
      for toctreenode in list(tree.findall(addnodes.toctree)):
          newnodes = []
          includefiles = map(str, toctreenode["includefiles"])
          for includefile in includefiles:
              if includefile not in traversed:
                  try:
                      traversed.append(includefile)
                      logger.info(
                          colorfunc(includefile) + " ", nonl=True
                      )
                      subtree = inline_all_toctrees(
                          builder,
                          docnameset,
                          includefile,
                          builder.env.get_doctree(includefile),
                          colorfunc,
                          traversed,
                      )
                      docnameset.add(includefile)
                  except Exception:
                      logger.warning(
                          __(
                              "toctree contains ref to nonexisting file %r"
                          ),
                          includefile,
                          location=docname,
                      )
                  else:
                      sof = addnodes.start_of_file(docname=includefile)
                      sof.children = subtree.children
                      for sectionnode in sof.findall(nodes.section):
                          if "docname" not in sectionnode:
                              sectionnode["docname"] = includefile
                      newnodes.append(sof)
          toctreenode.parent.replace(toctreenode, newnodes)
      return tree
  
imports: from __future__ import annotations
  import contextlib
  import re
  import unicodedata
  from typing import TYPE_CHECKING, Any, Callable
  from docutils import nodes
  from sphinx import addnodes
  from sphinx.locale import __
  from sphinx.util import logging
label_desc: Use image node_id 15 for calling a global function with example usage: inline_all_toctrees(builder, docnameset, docname, tree, colorfunc, traversed) and returns: tree