From d8b7fc0d720fb90a581826332a7592e1133d14ff Mon Sep 17 00:00:00 2001 From: lirc572 <34601854+lirc572@users.noreply.github.com> Date: Fri, 10 May 2019 10:52:58 +0800 Subject: [PATCH] add markdown support for color quotes and fix codeblocks for quotes https://github.com/hexojs/hexo/issues/2400 --- scripts/99_tags.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/scripts/99_tags.js b/scripts/99_tags.js index 30de1b83..ace2c4dd 100644 --- a/scripts/99_tags.js +++ b/scripts/99_tags.js @@ -3,5 +3,26 @@ */ hexo.extend.tag.register('colorquote', function (args, content) { var type = args[0]; - return '
' + content + '
'; -}, {ends: true}); \ No newline at end of file + return '
' + hexo.render.renderSync({text: content, engine: 'markdown'}) + '
'; +}, {ends: true}); + +const rEscapeContent = /]*)>([\s\S]*?)<\/escape>/g; +const placeholder = '\uFFFD'; +const rPlaceholder = /(?:<|<)\!--\uFFFD(\d+)--(?:>|>)/g; +const cache = []; +function escapeContent(str) { + return ''; +} +hexo.extend.filter.register('before_post_render', function(data) { + data.content = data.content.replace(rEscapeContent, function(match, content) { + return escapeContent(content); + }); + return data; +}); + +hexo.extend.filter.register('after_post_render', function(data) { + data.content = data.content.replace(rPlaceholder, function() { + return cache[arguments[1]]; + }); + return data; +});