Skip to content

Commit

Permalink
DisableNunjucks: true should render markdown code block (#3573)
Browse files Browse the repository at this point in the history
code block in markdown are not rendered correctly after set disableNunjucks to true
  • Loading branch information
JLHwung authored Jun 16, 2019
2 parents 61cbc62 + 6e6ee20 commit 9d09d2e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,12 @@ Post.prototype.render = function(source, data = {}, callback) {
engine: data.engine,
toString: true,
onRenderEnd(content) {
if (disableNunjucks) return content;
// Replace cache data with real contents
data.content = cacheObj.loadContent(content);

// Return content after replace the placeholders
if (disableNunjucks) return data.content;

// Render with Nunjucks
return tag.render(data.content, data);
}
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/post_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ exports.expected = [
'<blockquote><p>quote content</p>\n',
'<footer><strong>Hello World</strong></footer></blockquote>'
].join('');

exports.expected_disable_nunjucks = [
'<h1 id="Title"><a href="#Title" class="headerlink" title="Title"></a>Title</h1>',
util.highlight(code, {lang: 'python'}),
'\n\n<p>some content</p>\n',
'<h2 id="Another-title"><a href="#Another-title" class="headerlink" title="Another title"></a>Another title</h2>',
'<p>{% blockquote %}<br>',
'quote content<br>',
'{% endblockquote %}</p>\n',
'<p>{% quote Hello World %}<br>',
'quote content<br>',
'{% endquote %}</p>'
].join('');
31 changes: 31 additions & 0 deletions test/scripts/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,4 +686,35 @@ describe('Post', () => {
callback();
});
});

// test for PR [#3573](https://github.com/hexojs/hexo/pull/3573)
it('render() - (disableNunjucks === true)', () => {
const renderer = hexo.render.renderer.get('markdown');
renderer.disableNunjucks = true;

return post.render(null, {
content: fixture.content,
engine: 'markdown'
}).then(data => {
data.content.trim().should.eql(fixture.expected_disable_nunjucks);
}).then(data => {
renderer.disableNunjucks = false;
});
});

// test for PR [#3573](https://github.com/hexojs/hexo/pull/3573)
it('render() - (disableNunjucks === false)', () => {
const renderer = hexo.render.renderer.get('markdown');
renderer.disableNunjucks = false;

return post.render(null, {
content: fixture.content,
engine: 'markdown'
}).then(data => {
data.content.trim().should.eql(fixture.expected);
}).then(data => {
renderer.disableNunjucks = false;
});
});

});

0 comments on commit 9d09d2e

Please sign in to comment.