-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml-endnotes.js
More file actions
54 lines (54 loc) · 1.74 KB
/
Copy pathhtml-endnotes.js
File metadata and controls
54 lines (54 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* html-endnotes v1.1 (formerly jquery-endnotes)
* (c) 2020 Mitchell Golden
*
* html-endnotes is freely distributable under the terms of an MIT license.
* https://github.com/mgolden/html-endnotes
*--------------------------------------------------------------------------*/
document.addEventListener('DOMContentLoaded', (event) => {
let endnotesElement = document.getElementById("endnotes-here");
if(!endnotesElement) {
alert("Error: There is nowhere to put the list of endnotes.");
return;
}
let endnotesOl = document.createElement("ol");
endnotesOl.id = "endnotes";
endnotesElement.appendChild(endnotesOl);
let endnoteList = document.querySelectorAll("span[data-ref]");
let endnoteNum = 1;
for(let endnote of endnoteList) {
endnote.setAttribute("class", "endnote");
let refData = endnote.getAttribute("data-ref");
let refArr = refData.split("|");
let contentArr = new Array();
let link = "";
for (var i=0, l=refArr.length; i < l; i++) {
let ref = refArr[i].trim();
if(ref.substring(0,4)=="http") {
if(link!="") {
contentArr.push(link+"</a> ");
}
contentArr.push("<a href='"+ref+"' target='_blank'>");
link = ref;
}
else {
contentArr.push(ref);
if(link!="") {
contentArr.push("</a>");
}
contentArr.push(" ");
link = "";
}
}
if(link!="") {
contentArr.push(link+"</a>");
}
let newNote = document.createElement("span")
newNote.innerHTML = "<a href='#endnote-"+endnoteNum+"'><sup id='ref-"+endnoteNum+"'>"+endnoteNum+"</sup></a>";
endnote.appendChild(newNote);
let cite = document.createElement("li");
cite.id = "endnote-"+endnoteNum;
cite.innerHTML = "<a href='#ref-"+endnoteNum+"'>^</a> " + contentArr.join("");
endnotesOl.appendChild(cite);
endnoteNum++;
}
});