Browse Source

Changed old <aside> syntax to use {% sidenote %} tag

master
J David Smith 9 years ago
parent
commit
2f968cd60c
  1. 23
      scripts/aside.js

23
scripts/aside.js

@ -2,11 +2,18 @@ var jsdom = require('jsdom'),
crypto = require('crypto'),
util = require('util');
hexo.extend.filter.register('after_post_render', function(data) {
data.content = data.content.replace(/<aside>([^\r]+?)<\/aside>/mg, function(match, content) {
var id = crypto.createHash('sha256').update(content).digest('hex');
return util.format('<label for="%s" class="sidenote-number margin-toggle"></label>', id) +
util.format('<input type="checkbox" class="margin-toggle" id="%s">', id) +
'<span class="sidenote">' + content + "</span>";
});
});
hexo.extend.tag.register('sidenote', function(args, content) {
var id = crypto.createHash('sha256').update(content).digest('hex');
return util.format('<label for="%s" class="sidenote-number margin-toggle"></label>', id) +
util.format('<input type="checkbox" class="margin-toggle" id="%s">', id) +
'<span class="sidenote">' + hexo.render.renderSync({text: content, engine: 'md'}).replace(/<\/?p>/g, "") + "</span>";
}, {ends: true});
// repeated because adding several conditionals turns 2 4-line
// functions into a single hard-to-follow 10-line function
hexo.extend.tag.register('marginnote', function(args, content) {
var id = crypto.createHash('sha256').update(content).digest('hex');
return util.format('<label for="%s" class="margin-toggle">&#8853;</label>', id) +
util.format('<input type="checkbox" class="margin-toggle" id="%s">', id) +
'<span class="marginnote">' + hexo.render.renderSync({text: content, engine: 'md'}).replace(/<\/?p>/g, "") + "</span>";
}, {ends: true});
Loading…
Cancel
Save