added footnotes
This commit is contained in:
parent
22b93e71d8
commit
c63833ebba
6 changed files with 60 additions and 5 deletions
|
@ -29,7 +29,8 @@
|
|||
|
||||
<script src="https://cdn.jsdelivr.net/npm/showdown@1.9.0/dist/showdown.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/prettify.js"></script>
|
||||
<script src="scripts/showdown-prettify.js"></script>
|
||||
<script src="shared/showdown-prettify.js"></script>
|
||||
<script src="shared/showdown-footnotes.js"></script>
|
||||
|
||||
<script src="scripts/main.js"></script>
|
||||
</head>
|
||||
|
|
|
@ -2,12 +2,14 @@ const {
|
|||
JSDOM
|
||||
} = require("jsdom");
|
||||
const fs = require("fs");
|
||||
require("showdown-prettify");
|
||||
|
||||
const showdown = require("showdown");
|
||||
require("../shared/showdown-prettify");
|
||||
require("../shared/showdown-footnotes");
|
||||
const converter = new showdown.Converter({
|
||||
parseImgDimensions: true,
|
||||
headerLevelStart: 3,
|
||||
extensions: ["prettify"]
|
||||
extensions: ["prettify", "footnotes"]
|
||||
});
|
||||
|
||||
module.exports = function () {
|
||||
|
|
|
@ -2,9 +2,13 @@ const {
|
|||
Feed
|
||||
} = require("feed");
|
||||
const fs = require("fs");
|
||||
|
||||
const showdown = require("showdown");
|
||||
require("../shared/showdown-prettify");
|
||||
require("../shared/showdown-footnotes");
|
||||
const converter = new showdown.Converter({
|
||||
parseImgDimensions: true
|
||||
parseImgDimensions: true,
|
||||
extensions: ["prettify", "footnotes"]
|
||||
});
|
||||
|
||||
module.exports = function () {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
let converter = new showdown.Converter({
|
||||
parseImgDimensions: true,
|
||||
headerLevelStart: 3,
|
||||
extensions: ["prettify"]
|
||||
extensions: ["prettify", "footnotes"]
|
||||
});
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
|
|
46
shared/showdown-footnotes.js
Normal file
46
shared/showdown-footnotes.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
// 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) {
|
||||
return text.replace(/^\[\^([\d\w]+)\]:\s*((\n+(\s{2,4}|\t).+)+)$/mg, function (str, name, rawContent, _, padding) {
|
||||
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) {
|
||||
return text.replace(/^\[\^([\d\w]+)\]:( |\n)((.+\n)*.+)$/mg, function (str, name, _, content) {
|
||||
return '<a class="blog-anchor" id="footnote-' + name + '"></a><small class="footnote">[' + name + ']: ' + content + '</small>';
|
||||
});
|
||||
}
|
||||
}, {
|
||||
type: 'lang',
|
||||
filter: function filter(text) {
|
||||
return text.replace(/\[\^([\d\w]+)\]/m, function (str, name) {
|
||||
return '<a href="#footnote-' + name + '"><sup>[' + name + ']</sup></a>';
|
||||
});
|
||||
}
|
||||
}];
|
||||
});
|
||||
}));
|
||||
|
||||
//# sourceMappingURL=showdown-prettify.js.map
|
|
@ -1,3 +1,5 @@
|
|||
// Modified version of https://github.com/showdownjs/prettify-extension
|
||||
|
||||
/*! showdown-prettify 06-01-2016 */
|
||||
(function (extension) {
|
||||
'use strict';
|
Loading…
Reference in a new issue