Last active
January 4, 2021 19:45
-
-
Save murtaugh/6708871 to your computer and use it in GitHub Desktop.
Sniff out superscripts that should be footnote links
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
$('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> '); | |
}); |
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
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> |
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
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 :)