Skip to content

Instantly share code, notes, and snippets.

@vyder
Created September 14, 2020 12:29
Show Gist options
  • Save vyder/8d4bcd73a6df853d83580be2e590a17d to your computer and use it in GitHub Desktop.
Save vyder/8d4bcd73a6df853d83580be2e590a17d to your computer and use it in GitHub Desktop.
Markdown Footnotes
$(document).ready(function() {
// Find all footnotes
const $footnotes = $("ol:last > li");
const $refs = $("sup > a");
$footnotes.each(function(i, footnote) {
const num = (i + 1);
const $ref = $($refs[i]);
const $note = $(footnote);
// Setup the reference
$ref.html("[" + num + "]");
$ref.attr('href', "#fn:" + num);
$ref.parent().attr('id', "fnref:" + num);
// Setup the footnote
const $backLink = ($note.find("a:last"));
$note.attr('id', "fn:" + num);
$note.attr('role', "doc-endnote");
$backLink.attr('href', "#fnref:" + num);
$backLink.attr('role', "doc-backlink");
});
});
<sup role="doc-noteref"><a>[n]</a></sup>
<a href="#">↩</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment