Skip to content

Instantly share code, notes, and snippets.

Embed
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>
</ul>
@murtaugh

This comment has been minimized.

Copy link
Owner Author

murtaugh commented Sep 26, 2013

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

This comment has been minimized.

Copy link

equivalentideas commented Feb 11, 2014

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
You can’t perform that action at this time.