Skip to content

Commit

Permalink
fix(hexojs#2318): allow backtick code block in "blockquote" tag plugin (
Browse files Browse the repository at this point in the history
hexojs#2321)

* test(backtick): update comment

* Allow backtick code block in "blockquote" tag plugin (hexojs#2318)

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.

* require assert
  • Loading branch information
seaoak authored and Thomas Parisot committed Jan 17, 2020
1 parent f8472f5 commit 1769c9b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/hexo/post.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const assert = require('assert');
const moment = require('moment');
const Promise = require('bluebird');
const { join, extname } = require('path');
Expand Down Expand Up @@ -29,7 +30,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
26 changes: 24 additions & 2 deletions test/scripts/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ describe('Post', () => {
});
});

// test for PR [#3573](https://github.com/hexojs/hexo/pull/3573)
// test for PR #3573
it('render() - (disableNunjucks === true)', () => {
const renderer = hexo.render.renderer.get('markdown');
renderer.disableNunjucks = true;
Expand All @@ -702,7 +702,7 @@ describe('Post', () => {
});
});

// test for PR [#3573](https://github.com/hexojs/hexo/pull/3573)
// test for PR #3573
it('render() - (disableNunjucks === false)', () => {
const renderer = hexo.render.renderer.get('markdown');
renderer.disableNunjucks = false;
Expand All @@ -717,4 +717,26 @@ describe('Post', () => {
});
});

// test for PR #2321
it('render() - allow backtick code block in "blockquote" tag plugin', () => {
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 1769c9b

Please sign in to comment.