code: def _toctree_add_classes(
      node: Element, depth: int, docname: str
  ) -> None:
      """Add 'toctree-l%d' and 'current' classes to the toctree."""
      for subnode in node.children:
          if isinstance(
              subnode, (addnodes.compact_paragraph, nodes.list_item)
          ):
              # for <p> and <li>, indicate the depth level and recurse
              subnode["classes"].append(f"toctree-l{depth - 1}")
              _toctree_add_classes(subnode, depth, docname)
          elif isinstance(subnode, nodes.bullet_list):
              # for <ul>, just recurse
              _toctree_add_classes(subnode, depth + 1, docname)
          elif isinstance(subnode, nodes.reference):
              # for <a>, identify which entries point to the current
              # document and therefore may not be collapsed
              if subnode["refuri"] == docname:
                  if not subnode["anchorname"]:
                      # give the whole branch a 'current' class
                      # (useful for styling it differently)
                      branchnode: Element = subnode
                      while branchnode:
                          branchnode["classes"].append("current")
                          branchnode = branchnode.parent
                  # mark the list_item as "on current page"
                  if subnode.parent.parent.get("iscurrent"):
                      # but only if it's not already done
                      return
                  while subnode:
                      subnode["iscurrent"] = True
                      subnode = subnode.parent
  
imports: from __future__ import annotations
  from typing import TYPE_CHECKING, Any, TypeVar
  from docutils import nodes
  from docutils.nodes import Element, Node
  from sphinx import addnodes
  from sphinx.locale import __
  from sphinx.util import logging, url_re
  from sphinx.util.matching import Matcher
  from sphinx.util.nodes import _only_node_keep_children, clean_astext
label_desc: Use image node_id 11 for calling a global function with example usage: _toctree_add_classes(node, depth, docname) without return types