Skip to content

Commit

Permalink
Don't start from NaN (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinthomson authored Oct 3, 2024
1 parent 76153fb commit b877a56
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions charter.html
Original file line number Diff line number Diff line change
Expand Up @@ -697,15 +697,15 @@ <h2 id=about>About this Charter</h2>

<script>
document.addEventListener("DOMContentLoaded", function() {
let sectionCounters = [NaN, 0, 0, 0, 0, 0, 0];
let sectionCounters = [0, 0, 0, 0, 0, 0, 0];
document.querySelectorAll("[id]").forEach(function(elementWithID) {
const permalink = document.createElement("a");
permalink.href = "#" + elementWithID.getAttribute("id");
if (elementWithID instanceof HTMLHeadingElement) {
const headingLevel = parseInt(elementWithID.localName.substring(1), 10);
sectionCounters[headingLevel]++;
sectionCounters.fill(0, headingLevel + 1);
let sectionNumber = sectionCounters.slice(0, headingLevel + 1).filter(item => item != 0);
sectionCounters[headingLevel - 1]++;
sectionCounters.fill(0, headingLevel);
let sectionNumber = sectionCounters.slice(0, headingLevel).filter(item => item != 0);
sectionNumber = sectionNumber.join(".");
permalink.appendChild(document.createTextNode(sectionNumber + "."));
} else if (elementWithID instanceof HTMLTableRowElement) {
Expand Down

0 comments on commit b877a56

Please sign in to comment.