Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'));
});
});
});