Skip to content

Commit

Permalink
Allow backtick code block in "blockquote" tag plugin (hexojs#2318)
Browse files Browse the repository at this point in the history
When backtick code block(s) exist as contents of a "blockquote" tag plugin,
each code block is translated to a string "undefined" in HTML (Issue hexojs#2318).

In analyzing markdown source text, while the replacement of these elements
with placeholders are nesting, recoveries from placeholders are executed
only once.  So I modify to repeat the recovery process until all
placeholders are recovered.
  • Loading branch information
Seaoak committed Dec 19, 2016
1 parent 1da7ad5 commit bb9aaa5
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bb9aaa5

Please sign in to comment.