ion to convert string to title case
  function toTitleCase(str) {
    return str.replace(/\w\S*/g, function(txt){
      return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
    });
  }

  // Function to generate TOC
  function generateTOC(tabId, tocContainerId) {
    const tabContent = document.querySelector(tabId);
    const tocContainer = document.querySelector(tocContainerId);
    tocContainer.innerHTML = ''; // Clear previous TOC content

    console.log(`Generating TOC for: ${tabId}`);

  