Skip to content

Commit ac03b72

Browse files
authored
Merge pull request #3768 from seaoak/bugfix/backtick_code_block_on_blockquote_always_terminates_the_blockquote_block
fix: prevent inserting extra new line character into the end of backtick code block
2 parents 6b329e9 + 84c4c66 commit ac03b72

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

lib/plugins/filter/before_post_render/backtick_code_block.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function backtickCodeBlock(data) {
6363
.replace(/{/g, '{')
6464
.replace(/}/g, '}');
6565

66-
return `${start}<escape>${content}</escape>${end ? '\n\n' : ''}`;
66+
return `${start}<escape>${content}</escape>${end}`;
6767
});
6868
}
6969

test/fixtures/post_render.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ exports.content = content;
2929
exports.expected = [
3030
'<h1 id="Title"><a href="#Title" class="headerlink" title="Title"></a>Title</h1>',
3131
util.highlight(code, {lang: 'python'}),
32-
'\n\n<p>some content</p>\n',
32+
'\n<p>some content</p>\n',
3333
'<h2 id="Another-title"><a href="#Another-title" class="headerlink" title="Another title"></a>Another title</h2>',
3434
'<blockquote>',
3535
'<p>quote content</p>\n',
@@ -41,7 +41,7 @@ exports.expected = [
4141
exports.expected_disable_nunjucks = [
4242
'<h1 id="Title"><a href="#Title" class="headerlink" title="Title"></a>Title</h1>',
4343
util.highlight(code, {lang: 'python'}),
44-
'\n\n<p>some content</p>\n',
44+
'\n<p>some content</p>\n',
4545
'<h2 id="Another-title"><a href="#Another-title" class="headerlink" title="Another title"></a>Another title</h2>',
4646
'<p>{% blockquote %}<br>',
4747
'quote content<br>',

test/scripts/hexo/post.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,7 @@ describe('Post', () => {
734734
content
735735
}).then(data => {
736736
data.content.trim().should.eql([
737-
'<blockquote>' + highlighted,
738-
'</blockquote>'
737+
'<blockquote>' + highlighted + '</blockquote>'
739738
].join('\n'));
740739
});
741740
});
@@ -802,4 +801,40 @@ describe('Post', () => {
802801
});
803802
});
804803

804+
// test for Issue #3767
805+
it('render() - backtick cocde block (followed by a paragraph) in blockquote', () => {
806+
const code = 'alert("Hello world")';
807+
const highlighted = util.highlight(code);
808+
const quotedContent = [
809+
'This is a code-block',
810+
'',
811+
'```',
812+
code,
813+
'```',
814+
'',
815+
'This is a following paragraph'
816+
];
817+
818+
const content = [
819+
'Hello',
820+
'',
821+
...quotedContent.map(s => '> ' + s)
822+
].join('\n');
823+
824+
return post.render(null, {
825+
content,
826+
engine: 'markdown'
827+
}).then(data => {
828+
data.content.trim().should.eql([
829+
'<p>Hello</p>',
830+
'<blockquote>',
831+
'<p>This is a code-block</p>',
832+
highlighted,
833+
'',
834+
'<p>This is a following paragraph</p>',
835+
'</blockquote>'
836+
].join('\n'));
837+
});
838+
});
839+
805840
});

0 commit comments

Comments
 (0)