Skip to content

Instantly share code, notes, and snippets.

@harryfk
Last active August 29, 2015 14:10
Show Gist options
  • Save harryfk/84a7836d881429d35231 to your computer and use it in GitHub Desktop.
Save harryfk/84a7836d881429d35231 to your computer and use it in GitHub Desktop.
(function () {
var footnotes = function () {
return [
{ type: 'lang', filter: function(text) {
// Use footnotes like so: "foo[^1](This is the footnote text)"
var i = 0;
var inline_regex = /\[\^(\d|n)\]\((.*?)\)/g;
text = text.replace(inline_regex, function(match, n, t) {
// We allow both automatic and manual footnote numbering
if (n == "n") n = i+1;
var s = '<span class="footnote">' +
'<sup class="footnote__counter" tabindex="0">'+n+'</sup>' +
'<span class="footnote__text bg-color-secondary"><sup class="footnote__text__counter">'+n+'</sup>'+t+'</span>' +
'</span>';
i += 1;
return s;
});
return text;
}}
];
};
// Client-side export
if (typeof window !== 'undefined' && window.Showdown && window.Showdown.extensions) {
window.Showdown.extensions.footnotes = footnotes;
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment