Skip to content

Commit

Permalink
Merge 2ba4e14 into c5145ae
Browse files Browse the repository at this point in the history
  • Loading branch information
ksky521 committed Dec 14, 2015
2 parents c5145ae + 2ba4e14 commit e92c710
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/extend/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,30 @@ Tag.prototype.register = function(name, fn, options) {
this.env.addExtension(name, tag);
};

var placeholder = '\uFFFC';
var rPlaceholder = /(?:<|&lt;)\!--\uFFFC(\d+)--(?:>|&gt;)/g;

Tag.prototype.render = function(str, options, callback) {
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}

var cache = [];

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

var env = this.env;

return new Promise(function(resolve, reject) {
str = str.replace(/<pre><code.*>[\s\S]*?<\/code><\/pre>/gm, escapeContent);
env.renderString(str, options, function(err, result) {
if (err) return reject(err);
resolve(result);
resolve(result.replace(rPlaceholder, function() {
return cache[arguments[1]];
}));
});
});
};
Expand Down

0 comments on commit e92c710

Please sign in to comment.