code: def html_page_context(app, pagename, templatename, context, doctree):
      """Event handler for the html-page-context signal.
      Modifies the context directly.
       - Replaces the 'toc' value created by the HTML builder with one
         that shows all document titles and the local table of contents.
       - Sets display_toc to True so the table of contents is always
         displayed, even on empty pages.
       - Replaces the 'toctree' function with one that uses the entire
         document structure, ignores the maxdepth argument, and uses
         only prune and collapse.
      """
      rendered_toc = get_rendered_toctree(app.builder, pagename)
      context["toc"] = rendered_toc
      context["display_toc"] = True  # force toctree to display
  
      if "toctree" not in context:
          # json builder doesn't use toctree func, so nothing to replace
          return
  
      def make_toctree(collapse=True, maxdepth=-1, includehidden=True):
          return get_rendered_toctree(
              app.builder,
              pagename,
              prune=False,
              collapse=collapse,
          )
  
      context["toctree"] = make_toctree
  
imports: from sphinx import addnodes
label_desc: Use image node_id 1 for calling a global function with example usage: html_page_context(app, pagename, templatename, context, doctree) and returns: get_rendered_toctree