Add footnote jumping

This commit is contained in:
Valentin Boettcher 2019-01-11 11:03:46 +01:00
parent ddec5c6fb2
commit 4cd7b73df9
3 changed files with 49 additions and 3 deletions

4
.gitignore vendored
View file

@ -1,4 +1,4 @@
# -*- mode: gitignore; -*- # -*- mode: gitignore; -*-
*~ *~
\#*\# \#*\#
/.emacs.desktop /.emacs.desktop
@ -48,3 +48,5 @@ flycheck_*.el
/network-security.data /network-security.data
.ignored .ignored
web-ext-artifacts

View file

@ -108,15 +108,59 @@ function setUpNumbering() {
} }
}; };
function collectFootnotes() {
let footMap = [];
// collect al footnotes into pairs
for(let note of document.querySelectorAll('sup')) {
let index = parseInt(note.innerText) - 1;
// JS forces me to do that!
if(footMap[index])
footMap[index].push(note);
else
footMap[index] = [ note ];
}
return footMap;
}
function linkFootnotes() {
function identifyAndLink(index, originid, targetid, origin, target) {
origin.id = `foot${index}${originid}`;
let link = document.createElement('a');
target.id = `foot${index}${targetid}`;
link.href = '#' + target.id;
link.innerText = ++index;
origin.innerHTML = '';
origin.appendChild(link);
};
let footMap = collectFootnotes();
for(let index in footMap) {
let pair = footMap[index];
if(pair && pair.length == 2) {
let first = pair[0];
let second = pair[1];
identifyAndLink(index, 1, 2, first, second);
identifyAndLink(index, 2, 1, second, first);
}
}
}
// Let's apply that stuff. // Let's apply that stuff.
loadChapters().then(newChapters => { loadChapters().then(newChapters => {
chapters = newChapters; chapters = newChapters;
setUpNumbering(); setUpNumbering();
}); });
linkFootnotes();
wrapPre(); wrapPre();
HighlightLisp.highlight_auto(); HighlightLisp.highlight_auto();
HighlightLisp.paren_match(); HighlightLisp.paren_match();
createTOC(); createTOC();
setUpNav(); setUpNav();

View file

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Beautify Practical Common Lisp", "name": "Beautify Practical Common Lisp",
"version": "1.0", "version": "1.1",
"description": "Adds a simple table of contents and syntax highlighting to the web version of Practical Common Lisp by Peter Seibel.", "description": "Adds a simple table of contents and syntax highlighting to the web version of Practical Common Lisp by Peter Seibel.",