Last active
August 29, 2015 14:10
-
-
Save harryfk/84a7836d881429d35231 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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