You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
1.1 KiB

9 years ago
  1. var jsdom = require('jsdom'),
  2. crypto = require('crypto'),
  3. util = require('util');
  4. hexo.extend.tag.register('sidenote', function(args, content) {
  5. var id = crypto.createHash('sha256').update(content).digest('hex');
  6. return util.format('<label for="%s" class="sidenote-number margin-toggle"></label>', id) +
  7. util.format('<input type="checkbox" class="margin-toggle" id="%s">', id) +
  8. '<span class="sidenote">' + hexo.render.renderSync({text: content, engine: 'md'}).replace(/<\/?p>/g, "") + "</span>";
  9. }, {ends: true});
  10. // repeated because adding several conditionals turns 2 4-line
  11. // functions into a single hard-to-follow 10-line function
  12. hexo.extend.tag.register('marginnote', function(args, content) {
  13. var id = crypto.createHash('sha256').update(content).digest('hex');
  14. return util.format('<label for="%s" class="margin-toggle">&#8853;</label>', id) +
  15. util.format('<input type="checkbox" class="margin-toggle" id="%s">', id) +
  16. '<span class="marginnote">' + hexo.render.renderSync({text: content, engine: 'md'}).replace(/<\/?p>/g, "") + "</span>";
  17. }, {ends: true});