Last active
May 23, 2020 02:44
-
-
Save kmelve/7926073 to your computer and use it in GitHub Desktop.
Takes HTML with footnotes generated in Word and – using jQuery – converts it to syntax compatible with [Bigfoot.js](http://cmsauve.com/labs/bigfoot/). I use it for a wordpress install. This is the first iteration of the code, and it can certainly be improved. I guess most of it can be done in pure Javascript.
This file contains 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
var notes = []; | |
$('a[href*="ftnref"]').each(function (i) { | |
n = i + 1; | |
notes.push($(this[i]).parent().text()); | |
$(this).parent().wrap('<li class="footnote" id=fn:' + n + '>' + notes[i] + '</li>'); | |
$(this).remove(); | |
}); | |
$('.footnote').parent().wrapAll('<div class="footnotes" />'); | |
$('div > .footnote').unwrap(); | |
$('.footnotes').wrapInner('<ol></ol>'); | |
var footnoteref = []; | |
$('a[href*="_ftn"]').each(function (i) { | |
$(this).attr('rel','footnote'); | |
footnoteref.push($(this[i]).parent().text()); | |
n = i + 1; | |
$(this[i]).attr("href", function () { | |
return '#fn:' + n; | |
}); | |
$(this).removeAttr( "title" ); | |
$(this).removeAttr( "style" ); | |
$(this).text(function () { | |
return $(this).text().replace(/\[(\d*)\]/gi, "$1"); | |
}); | |
$(this).wrap('<sup id="fnref:' + n + '>' + footnoteref[i] + '</sup>'); | |
}); | |
$('a[href*="_ftn"]').each(function (i) { | |
i = i + 1; | |
footnotelink = '#fn:'; | |
$(this).attr('href', function () { | |
return footnotelink + i; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is a great code. Today it still works. With a few minor modifications: