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

Disable to insert extra new line character into the end of backtick code block (fix #3767) #3768

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
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
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
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'));
});
});

});