code: def get_rendered_toctree(
      builder, docname, prune=False, collapse=True
  ):
      """Build the toctree relative to the named document,
      with the given parameters, and then return the rendered
      HTML fragment.
      """
      fulltoc = build_full_toctree(
          builder,
          docname,
          prune=prune,
          collapse=collapse,
      )
      rendered_toc = builder.render_partial(fulltoc)["fragment"]
      return rendered_toc
  
imports: from sphinx import addnodes
label_desc: Use image node_id 2 for calling a global function with example usage: get_rendered_toctree(builder, docname, prune, collapse) and returns: rendered_toc