Skip to content

Instantly share code, notes, and snippets.

@westonruter
Created December 16, 2009 17:56
Show Gist options
  • Save westonruter/258017 to your computer and use it in GitHub Desktop.
Save westonruter/258017 to your computer and use it in GitHub Desktop.
ESV API Footnote Fix: The HTML marking up the footnotes returned by the ESV API is undesirable. Each footnote is separated from following footnotes by <br> elements. This function places each footnote inside of a <li> and adds the ID of the link inside.
/**
* The HTML marking up the footnotes returned by the ESV API is undesirable.
* Each footnote is separated from following footnotes by <br> elements:
* <span class="footnote"><a href="#b1" id="f1">[1]</a></span> <span class="footnote-ref">1:6</span> ...<br />
* This function places each footnote inside of a <li> and adds the ID of the
* link inside.
* Created for http://pixelfaith.com/bible/
*/
function fixFootersForESVHTML(){
var footnotes = document.querySelector('.footnotes > p');
var li,ul = document.createElement('ul');
//Now iterate over the footnotes.childNodes and construct lis out of them
var node;
while(node = footnotes.firstChild){
if(node.nodeType == 1/*Node.ELEMENT_NODE*/){
if(/(^|\s)footnote($|\s)/.test(node.className)){
li = document.createElement('li');
ul.appendChild(li);
//Move the ID from the link to the li
var link = node.getElementsByTagName('a')[0];
var id = link.id;
link.removeAttribute('id');
li.id = id;
}
//Ignore and remove all br elements
else if(node.localName.toLowerCase() == 'br'){
footnotes.removeChild(node);
continue;
}
}
if(li)
li.appendChild(node);
}
footnotes.parentNode.replaceChild(ul, footnotes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment