Skip to content

Commit

Permalink
Update main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
pmjklemm authored Sep 13, 2024
1 parent 3d0dd30 commit ad92e87
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ function ChangeSelect(TxtBox) {
}
function GenerateScrollSpy() {
let currentUl = $('<ul></ul>'); // Start with an empty list
let currentH1 = null; // Track the current <h1>
let currentH = null; // Track the current <h1>

$('h1, h2').each(function (index, element) {
$('h2, h3').each(function (index, element) {
const tag = $(element).prop('tagName');

if (tag === 'H1') {
currentH1 = $('<li><a href="#' + $(element).attr('id') + '">' + $(element).text() + '</a></li>');
if (tag === 'H2') {
currentH = $('<li><a href="#' + $(element).attr('id') + '">' + $(element).text() + '</a></li>');
currentUl = $('<ul></ul>'); // Create a new <ul> for nested h2 elements
currentH1.append(currentUl);
$('#TableOfContents').children().eq(0).append(currentH1);
} else if (tag === 'H2' && currentH1) {
currentH.append(currentUl);
$('#TableOfContents').children().eq(0).append(currentH);
} else if (tag === 'H3' && currentH) {
currentUl.append('<li><a style="font-size:0.8rem" href="#' + $(element).attr('id') + '">' + $(element).text() + '</a></li>');
}
});
Expand Down

0 comments on commit ad92e87

Please sign in to comment.