Skip to content

Instantly share code, notes, and snippets.

@kmelve
Last active May 23, 2020 02:44
Show Gist options
  • Save kmelve/7926073 to your computer and use it in GitHub Desktop.
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.
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;
});
});
@RbnAlexs
Copy link

RbnAlexs commented May 23, 2020

It is a great code. Today it still works. With a few minor modifications:

$('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').wrapAll('<div class="footnotes"></div>');
$('.footnotes').wrapInner('<ol></ol>');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment