Skip to content

Commit

Permalink
disable Nunjucks when the renderer spcify that (#2593)
Browse files Browse the repository at this point in the history
* disable disableNunjucks when the renderer spcify that

* format

* source may be empty

* correct styling
  • Loading branch information
be5invis authored and NoahDragon committed Jun 2, 2017
1 parent b76a7b2 commit 2d0af81
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions lib/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,26 @@ Post.prototype.render = function(source, data, callback) {
var config = ctx.config;
var cache = [];
var tag = ctx.extend.tag;
var isSwig = data.engine === 'swig' || (source && pathFn.extname(source) === '.swig');
var ext = data.engine || (source ? pathFn.extname(source) : '');

var isSwig = ext === 'swig';

var disableNunjucks = false;

if (ext && ctx.render.renderer.get(ext)) {

// disable Nunjucks when the renderer spcify that.

disableNunjucks = disableNunjucks || !!ctx.render.renderer.get(ext).disableNunjucks;

}

function escapeContent(str) {
return '<!--' + placeholder + (cache.push(str) - 1) + '-->';
}

function tagFilter(content) {
if (disableNunjucks) return content;
// Replace cache data with real contents
content = content.replace(rPlaceholder, function() {
return cache[arguments[1]];
Expand Down Expand Up @@ -273,11 +286,13 @@ Post.prototype.render = function(source, data, callback) {
if (isSwig) return data.content;

// Escape all Swig tags
data.content = data.content
.replace(rSwigFullBlock, escapeContent)
.replace(rSwigBlock, escapeContent)
.replace(rSwigComment, '')
.replace(rSwigVar, escapeContent);
if (!disableNunjucks) {
data.content = data.content
.replace(rSwigFullBlock, escapeContent)
.replace(rSwigBlock, escapeContent)
.replace(rSwigComment, '')
.replace(rSwigVar, escapeContent);
}

var options = data.markdown || {};
if (!config.highlight.enable) options.highlight = null;
Expand Down

0 comments on commit 2d0af81

Please sign in to comment.