Skip to content

Instantly share code, notes, and snippets.

Last active January 4, 2021 19:45
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Sniff out superscripts that should be footnote links
$('sup[data-footnote]').each(function(index) {
noteCount = $(this).html();
$(this).html('<a id="ref' + noteCount + '" href="#note' + noteCount + '">' + noteCount + '</a>');
$('#footnotes li').eq(noteCount - 1).attr('id', 'note' + noteCount).prepend('<a href="#ref' + noteCount + '">' + noteCount + '.</a> ');
The footnote indicator looks like this.<sup data-footnote>1</sup>
A second one looks like this.<sup data-footnote>2</sup>
The script expects the footnotes to look like this; it could be UL or OL, up to you, just know
the script prepends the count to the LI, so use CSS to hide the native bullets:
<ul id="footnotes">
<li>Footnote text for the first one.</li>
<li>Footnote text for the second one.</li>
Copy link

You could also use this to generate all the link markup and then copy that back into the original content, then you'd have it without the script having to run, or I'm sure someone could make it a grunt task. I know you addressed this above, just sparked an idea :) thanks for the script.

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