diff --git a/lib/hexo/post.js b/lib/hexo/post.js index 52c2edfe95..f81ee3cc03 100644 --- a/lib/hexo/post.js +++ b/lib/hexo/post.js @@ -244,9 +244,25 @@ Post.prototype.render = function(source, data, callback) { function tagFilter(content) { // Replace cache data with real contents - content = content.replace(rPlaceholder, function() { - return cache[arguments[1]]; - }); + var isMatching; + + function readCache(substr, p1) { + var index = +p1; + if (cache[index] === undefined) throw new Error('Unexpected placeholder!'); + var ans = cache[index]; + cache[index] = undefined; + isMatching = true; + return ans; + } + + content = content.replace(rPlaceholder, readCache); + if (isMatching) return tagFilter(content); + + function isElementNotUndefined(elem, index, arr) { + return elem !== undefined; + } + + if (cache.some(isElementNotUndefined)) throw new Error('Unmatched placeholder remains!'); // Render with Nunjucks data.content = content;