Skip to content

Commit

Permalink
add markdown support for color quotes and fix codeblocks for quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
lirc572 authored and zxzsaga committed Feb 26, 2020
1 parent acca646 commit fe4334b
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions scripts/99_tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,26 @@
*/
hexo.extend.tag.register('colorquote', function (args, content) {
var type = args[0];
return '<blockquote class="colorquote ' + type + '">' + content + '</blockquote>';
}, {ends: true});
return '<blockquote class="colorquote ' + type + '">' + hexo.render.renderSync({text: content, engine: 'markdown'}) + '</blockquote>';
}, {ends: true});

const rEscapeContent = /<escape(?:[^>]*)>([\s\S]*?)<\/escape>/g;
const placeholder = '\uFFFD';
const rPlaceholder = /(?:<|&lt;)\!--\uFFFD(\d+)--(?:>|&gt;)/g;
const cache = [];
function escapeContent(str) {
return '<!--' + placeholder + (cache.push(str) - 1) + '-->';
}
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;
});

0 comments on commit fe4334b

Please # to comment.