From 4cd7b73df92ed7b12d45008af02a7047a2b29f95 Mon Sep 17 00:00:00 2001 From: Valentin Boettcher Date: Fri, 11 Jan 2019 11:03:46 +0100 Subject: [PATCH] Add footnote jumping --- .gitignore | 6 ++++-- js/main.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ manifest.json | 2 +- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8a3b740..2564150 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -# -*- mode: gitignore; -*- + # -*- mode: gitignore; -*- *~ \#*\# /.emacs.desktop @@ -47,4 +47,6 @@ flycheck_*.el # network security /network-security.data -.ignored \ No newline at end of file +.ignored + +web-ext-artifacts \ No newline at end of file diff --git a/js/main.js b/js/main.js index aede5cb..a675521 100644 --- a/js/main.js +++ b/js/main.js @@ -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. loadChapters().then(newChapters => { chapters = newChapters; setUpNumbering(); }); +linkFootnotes(); wrapPre(); HighlightLisp.highlight_auto(); HighlightLisp.paren_match(); createTOC(); setUpNav(); + diff --git a/manifest.json b/manifest.json index 12741e3..70a501e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "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.",