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 authored and curbengh committed Oct 10, 2019
1 parent bd70086 commit 3c865c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ PostRenderCache.prototype.escapeContent = function(str) {

PostRenderCache.prototype.loadContent = function(str) {
const rPlaceholder = /(?:<|&lt;)!--\uFFFC(\d+)--(?:>|&gt;)/g;
return str.replace(rPlaceholder, (_, index) => this.cache[index]);
const restored = str.replace(rPlaceholder, (_, index) => {
assert(this.cache[index]);
const value = this.cache[index];
this.cache[index] = null;
return value;
});
if (restored === str) return restored;
return this.loadContent(restored); // self-recursive for nexted escaping
};

PostRenderCache.prototype.escapeAllSwigTags = function(str) {
Expand Down
22 changes: 22 additions & 0 deletions test/scripts/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,4 +717,26 @@ describe('Post', () => {
});
});

// test for Issue [#2318](https://github.com/hexojs/hexo/issues/2318)
it('render() - allow backtick code block in "blockquote" tag plugn (Issue#2318)', () => {
const code = 'alert("Hello world")';
const highlighted = util.highlight(code);

const content = [
'{% blockquote %}',
'```',
code,
'```',
'{% endblockquote %}'
].join('\n');

return post.render(null, {
content
}).then(data => {
data.content.trim().should.eql([
'<blockquote>' + highlighted,
'</blockquote>'
].join('\n'));
});
});
});

0 comments on commit 3c865c8

Please sign in to comment.