Created
December 5, 2023 13:28
-
-
Save alissa-maria/090fe71629f165f7c958d9d36dcbb4ab to your computer and use it in GitHub Desktop.
Collects footnote data in article elements and generates appropriate HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| document.addEventListener("DOMContentLoaded", function () { | |
| const articles = document.querySelectorAll("article"); | |
| articles.forEach((article) => { | |
| // Looks for (span) elements with footnote class | |
| const footnotes = article.querySelectorAll(".footnote"); | |
| // Creates a separator if there are footnotes present | |
| if (footnotes.length > 0) { | |
| const hrElement = document.createElement("hr"); | |
| article.appendChild(hrElement); | |
| } | |
| footnotes.forEach((footnote, index) => { | |
| // Generates and sets the footnote number | |
| const footnoteNumber = index + 1; | |
| footnote.innerHTML = `<sup>${footnoteNumber}</sup>`; | |
| // Creates the footnote content and appends it to the end of the article | |
| const footnoteContent = footnote.getAttribute("data-content"); | |
| const footnoteElement = document.createElement("div"); | |
| footnoteElement.classList.add("footnote-content"); | |
| footnoteElement.innerHTML = `<b>${footnoteNumber}:</b> ${footnoteContent}`; | |
| article.appendChild(footnoteElement); | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment