diff --git a/lib/plugins/filter/before_post_render/backtick_code_block.js b/lib/plugins/filter/before_post_render/backtick_code_block.js index 8120b39f4f..ce01af6770 100644 --- a/lib/plugins/filter/before_post_render/backtick_code_block.js +++ b/lib/plugins/filter/before_post_render/backtick_code_block.js @@ -63,7 +63,7 @@ function backtickCodeBlock(data) { .replace(/{/g, '{') .replace(/}/g, '}'); - return `${start}${content}${end ? '\n\n' : ''}`; + return `${start}${content}${end}`; }); } diff --git a/test/fixtures/post_render.js b/test/fixtures/post_render.js index 829c64b48c..931dfd08cc 100644 --- a/test/fixtures/post_render.js +++ b/test/fixtures/post_render.js @@ -29,7 +29,7 @@ exports.content = content; exports.expected = [ '

Title

', util.highlight(code, {lang: 'python'}), - '\n\n

some content

\n', + '\n

some content

\n', '

Another title

', '
', '

quote content

\n', @@ -41,7 +41,7 @@ exports.expected = [ exports.expected_disable_nunjucks = [ '

Title

', util.highlight(code, {lang: 'python'}), - '\n\n

some content

\n', + '\n

some content

\n', '

Another title

', '

{% blockquote %}
', 'quote content
', diff --git a/test/scripts/hexo/post.js b/test/scripts/hexo/post.js index 5aab2c8055..9ed1d2a42f 100644 --- a/test/scripts/hexo/post.js +++ b/test/scripts/hexo/post.js @@ -734,8 +734,7 @@ describe('Post', () => { content }).then(data => { data.content.trim().should.eql([ - '

' + highlighted, - '
' + '
' + highlighted + '
' ].join('\n')); }); }); @@ -802,4 +801,40 @@ describe('Post', () => { }); }); + // test for Issue #3767 + it('render() - backtick cocde block (followed by a paragraph) in blockquote', () => { + const code = 'alert("Hello world")'; + const highlighted = util.highlight(code); + const quotedContent = [ + 'This is a code-block', + '', + '```', + code, + '```', + '', + 'This is a following paragraph' + ]; + + const content = [ + 'Hello', + '', + ...quotedContent.map(s => '> ' + s) + ].join('\n'); + + return post.render(null, { + content, + engine: 'markdown' + }).then(data => { + data.content.trim().should.eql([ + '

Hello

', + '
', + '

This is a code-block

', + highlighted, + '', + '

This is a following paragraph

', + '
' + ].join('\n')); + }); + }); + });