/* Javascript functions to help make the print page more PDF friendly */ /* Generates a table of contents for the print site page. Only called when print-site-plugin option 'add_table_of_contents' is set to true */ function generate_toc() { var ToC = "" var newLine, el, title, link; const toc_elements = document.querySelectorAll( "#print-site-page h1.nav-section-title, #print-site-page h1.nav-section-title-end," + "#print-site-page h2.nav-section-title, #print-site-page h2.nav-section-title-end," + "#print-site-page h3.nav-section-title, #print-site-page h3.nav-section-title-end," + "#print-site-page h4.nav-section-title, #print-site-page h4.nav-section-title-end," + "#print-site-page h5.nav-section-title, #print-site-page h5.nav-section-title-end," + "#print-site-page h6.nav-section-title, #print-site-page h6.nav-section-title-end," + "section.print-page h1,section.print-page h2,section.print-page h3," + "section.print-page h4,section.print-page h5,section.print-page h6") var current_heading_depth = 0; var current_section_depth = 0; // Extract table of contents depth // basically plugin setting, passed via a data attribute var toc_depth = document.getElementById("print-page-toc").getAttribute("data-toc-depth") for (var i = 0; i < toc_elements.length; i++) { // Get the info from the element el = toc_elements[i] link = "#" + el.id; tag = el.tagName tag_level = tag.substring(1) // Get the text of a heading // We use .firstChild.nodeValue instead of .innerText // because of elements like: //

// mkdocs-print-site-plugin //

title = el.firstChild.nodeValue; if ( ! title ) { continue; } // Don't put the toc h1 in the toc if ( el.classList.contains('print-page-toc-title') ) { continue; } // Ignore the MkDocs keyboard Model if ( el.id.indexOf("keyboardModalLabel") > -1 ) { continue; } // print-site-plugin has a setting to control TOC depth if ( tag_level > toc_depth ) { continue; } if (el.classList.contains('nav-section-title') ) { // Use the tag level of the first item in the section to close off any nested " document.querySelectorAll("#print-page-toc nav")[0].insertAdjacentHTML("beforeend", ToC); }