.active`);
    const tocContainer = document.querySelector('#quarto-margin-sidebar-toc');
    if (activeTab) {
      generateTOC(`#${activeTab.id}`, '#quarto-margin-sidebar-toc');
    }
  }

  // Create and insert TOC container if it doesn't exist
  function createTOCContainer() {
    const sidebar = document.querySelector('#quarto-margin-sidebar');
    if (sidebar) {
      const existingTOC = document.querySelector('#quarto-margin-sidebar-toc');
      if (!existingTOC) {
        const tocContainer = docume