Skip to content

Commit

Permalink
Disable to insert extra new line character into the end of backtick c…
Browse files Browse the repository at this point in the history
…ode block (fix #3767)

A paragraph follows a backtick code block on a blockquote should be included same blcokquote block.
But the code block always terminates blockquote.
So the blockquote block splits two blocks.

This is caused by the implementation of `backtick_code_block.js`.
It inserts extra new line character into the end of backtick code block.

This patch disables this behavior.
  • Loading branch information
seaoak committed Oct 15, 2019
1 parent 6b329e9 commit 84c4c66
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function backtickCodeBlock(data) {
.replace(/{/g, '{')
.replace(/}/g, '}');

return `${start}<escape>${content}</escape>${end ? '\n\n' : ''}`;
return `${start}<escape>${content}</escape>${end}`;
});
}

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/post_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports.content = content;
exports.expected = [
'<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',
'\n<p>some content</p>\n',
'<h2 id="Another-title"><a href="#Another-title" class="headerlink" title="Another title"></a>Another title</h2>',
'<blockquote>',
'<p>quote content</p>\n',
Expand All @@ -41,7 +41,7 @@ exports.expected = [
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',
'\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>',
Expand Down
39 changes: 37 additions & 2 deletions test/scripts/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,7 @@ describe('Post', () => {
content
}).then(data => {
data.content.trim().should.eql([
'<blockquote>' + highlighted,
'</blockquote>'
'<blockquote>' + highlighted + '</blockquote>'
].join('\n'));
});
});
Expand Down Expand Up @@ -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([
'<p>Hello</p>',
'<blockquote>',
'<p>This is a code-block</p>',
highlighted,
'',
'<p>This is a following paragraph</p>',
'</blockquote>'
].join('\n'));
});
});

});

0 comments on commit 84c4c66

Please sign in to comment.