Skip to content

Instantly share code, notes, and snippets.

@murtaugh
Last active January 4, 2021 19:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save murtaugh/6708871 to your computer and use it in GitHub Desktop.
Save murtaugh/6708871 to your computer and use it in GitHub Desktop.
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>
</ul>
@murtaugh
Copy link
Author

Before you ask, yes I have decided that un-linked footnotes in non-JS environments are fine with me.

People generally know where footnotes are going to be :)

@equivalentideas
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