code: def setup_context(app, pagename, templatename, context, doctree):
      @lru_cache(maxsize=None)
      def render_header_nav_links() -> bs4.BeautifulSoup:
          """Render external header links into the top nav bar.
          The structure rendered here is defined in an external yaml file.
  
          Returns
          -------
          str
              Raw HTML to be rendered in the top nav bar
          """
          if not hasattr(app.config, "navbar_content"):
              raise ValueError(
                  "A template is attempting to call render_header_nav_links(); a "
                  "navbar configuration must be specified."
              )
  
          node = nodes.container(classes=["navbar-content"])
          node.append(render_header_nodes(app.config.navbar_content))
          header_soup = bs4.BeautifulSoup(
              app.builder.render_partial(node)["fragment"],
              "html.parser",
          )
          return add_nav_chevrons(header_soup)
  
      def render_header_nodes(
          obj: List[NavEntry], is_top_level: bool = True
      ) -> nodes.Node:
          """Generate a set of header nav links with docutils nodes.
  
          Parameters
          ----------
          is_top_level : bool
              True if the call to this function is rendering the top level nodes,
              False otherwise (non-top level nodes are displayed as submenus of the top
              level nodes)
          obj : List[NavEntry]
              List of yaml config entries to render as docutils nodes
  
          Returns
          -------
          nodes.Node
              Bullet list which will be turned into header nav HTML by the sphinx builder
          """
          bullet_list = nodes.bullet_list(
              bullet="-",
              classes=[
                  "navbar-toplevel"
                  if is_top_level
                  else "navbar-sublevel"
              ],
          )
  
          for item in obj:
              if "file" in item:
                  ref_node = make_refnode(
                      app.builder,
                      context["current_page_name"],
                      item["file"],
                      None,
                      nodes.inline(
                          classes=["navbar-link-title"],
                          text=item.get("title"),
                      ),
                      item.get("title"),
                  )
              elif "link" in item:
                  ref_node = nodes.reference("", "", internal=False)
                  ref_node["refuri"] = item.get("link")
                  ref_node["reftitle"] = item.get("title")
                  ref_node.append(
                      nodes.inline(
                          classes=["navbar-link-title"],
                          text=item.get("title"),
                      )
                  )
  
              if "caption" in item:
                  caption = nodes.Text(item.get("caption"))
                  ref_node.append(caption)
  
              paragraph = nodes.paragraph()
              paragraph.append(ref_node)
  
              container = nodes.container(classes=["ref-container"])
              container.append(paragraph)
  
              list_item = nodes.list_item(
                  classes=["active-link"]
                  if item.get("file") == pagename
                  else []
              )
              list_item.append(container)
  
              if "sections" in item:
                  wrapper = nodes.container(classes=["navbar-dropdown"])
                  wrapper.append(
                      render_header_nodes(
                          item["sections"], is_top_level=False
                      )
                  )
                  list_item.append(wrapper)
  
              bullet_list.append(list_item)
  
          return bullet_list
  
      context["cached_toctree"] = preload_sidebar_nav(
          context["toctree"],
          context["pathto"],
          context["root_doc"],
          pagename,
      )
      context["render_header_nav_links"] = render_header_nav_links
  
      # Update the HTML page context with a few extra utilities.
      context["pygments_highlight_python"] = lambda code: highlight(
          code, PythonLexer(), HtmlFormatter()
      )
  
imports: import re
  import sphinx
  from typing import List, Dict, Union, Callable, Any
  import copy
  import yaml
  import bs4
  import logging
  import logging.handlers
  import pathlib
  import urllib
  import urllib.request
  from queue import Queue
  import requests
  from preprocess_github_markdown import preprocess_github_markdown_file
  from sphinx.util import logging
  from sphinx.util.console import red
  from sphinx.util.nodes import make_refnode
  from docutils import nodes
  from functools import lru_cache
  from pydata_sphinx_theme.toctree import add_collapse_checkboxes
  from pygments import highlight
  from pygments.lexers import PythonLexer
  from pygments.formatters import HtmlFormatter
label_desc: Use image node_id 5 for calling a global function with example usage: setup_context(app, pagename, templatename, context, doctree) and returns: add_nav_chevrons, bullet_list