Web/node/lib/showdown-footnotes.js

46 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-10-09 23:43:40 +02:00
// Modified version of https://github.com/Kriegslustig/showdown-footnotes
/*! showdown-prettify 06-01-2016 */
(function (extension) {
'use strict';
if (typeof showdown !== 'undefined') {
extension(showdown);
} else if (typeof define === 'function' && define.amd) {
define(['showdown'], extension);
} else if (typeof exports === 'object') {
module.exports = extension(require('showdown'));
} else {
throw Error('Could not find showdown library');
}
}(function (showdown) {
'use strict';
showdown.extension('footnotes', function () {
return [{
type: 'lang',
filter: function filter(text) {
2019-10-10 01:42:04 +02:00
return text.replace(/\[\^([\d\w]+)\]:\s*((\n+(\s{2,4}|\t).+)+)/mgi, function (str, name, rawContent, _, padding) {
2019-10-09 23:43:40 +02:00
var content = converter.makeHtml(rawContent.replace(new RegExp('^' + padding, 'gm'), ''));
return '<a class="blog-anchor" id="footnote-' + name + '"></a><div class="footnote">[' + name + ']:' + content + '</div>';
});
}
}, {
type: 'lang',
filter: function filter(text) {
2019-10-10 01:42:04 +02:00
return text.replace(/\[\^([\d\w]+)\]:( |\n)((.+\n)*.+)/mgi, function (str, name, _, content) {
return '<a class="blog-anchor" id="footnote-' + name + '"></a><small class="footnote"><a href="#footnote-reference-' + name + '">[' + name + ']</a>: ' + content + '</small>';
2019-10-09 23:43:40 +02:00
});
}
}, {
type: 'lang',
filter: function filter(text) {
2019-10-10 00:30:46 +02:00
return text.replace(/\[\^([\d\w]+)\]/mgi, function (str, name) {
2019-10-10 01:42:04 +02:00
return '<a class="blog-anchor" id="footnote-reference-' + name + '"><a href="#footnote-' + name + '"><sup>[' + name + ']</sup></a>';
2019-10-09 23:43:40 +02:00
});
}
}];
});
}));
//# sourceMappingURL=showdown-prettify.js.map