Skip to content
This repository was archived by the owner on Jun 4, 2022. It is now read-only.

Commit 469db43

Browse files
authored
Merge pull request #101 from lirc572/master
add markdown support for color quotes and fix code block for {% raw %}
2 parents 29ea81e + d8b7fc0 commit 469db43

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

scripts/99_tags.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,26 @@
33
*/
44
hexo.extend.tag.register('colorquote', function (args, content) {
55
var type = args[0];
6-
return '<blockquote class="colorquote ' + type + '">' + content + '</blockquote>';
7-
}, {ends: true});
6+
return '<blockquote class="colorquote ' + type + '">' + hexo.render.renderSync({text: content, engine: 'markdown'}) + '</blockquote>';
7+
}, {ends: true});
8+
9+
const rEscapeContent = /<escape(?:[^>]*)>([\s\S]*?)<\/escape>/g;
10+
const placeholder = '\uFFFD';
11+
const rPlaceholder = /(?:<|&lt;)\!--\uFFFD(\d+)--(?:>|&gt;)/g;
12+
const cache = [];
13+
function escapeContent(str) {
14+
return '<!--' + placeholder + (cache.push(str) - 1) + '-->';
15+
}
16+
hexo.extend.filter.register('before_post_render', function(data) {
17+
data.content = data.content.replace(rEscapeContent, function(match, content) {
18+
return escapeContent(content);
19+
});
20+
return data;
21+
});
22+
23+
hexo.extend.filter.register('after_post_render', function(data) {
24+
data.content = data.content.replace(rPlaceholder, function() {
25+
return cache[arguments[1]];
26+
});
27+
return data;
28+
});

0 commit comments

Comments
 (0)