diff --git a/lib/plugins/filter/before_post_render/backtick_code_block.ts b/lib/plugins/filter/before_post_render/backtick_code_block.ts
index b9df3e60f2..802ed7edd3 100644
--- a/lib/plugins/filter/before_post_render/backtick_code_block.ts
+++ b/lib/plugins/filter/before_post_render/backtick_code_block.ts
@@ -1,4 +1,4 @@
-const rBacktick = /^((?:[^\S\r\n]*>){0,3}[^\S\r\n]*)(`{3,}|~{3,})[^\S\r\n]*((?:.*?[^`\s])?)[^\S\r\n]*\n((?:[\s\S]*?\n)?)(?:(?:[^\S\r\n]*>){0,3}[^\S\r\n]*)\2[^\S\r\n]?(\n+|$)/gm;
+const rBacktick = /^((?:[^\S\r\n]*>){0,3}[^\S\r\n]*)(`{3,}|~{3,})[^\S\r\n]*((?:.*?[^`\s])?)[^\S\r\n]*\n((?:[\s\S]*?\n)*?)(?:(?:[^\S\r\n]*>){0,3}[^\S\r\n]*)\2[^\S\r\n]?(\n+|$)/gm;
const rAllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/;
const rLangCaption = /([^\s]+)\s*(.+)?/;
diff --git a/test/scripts/filters/backtick_code_block.js b/test/scripts/filters/backtick_code_block.js
index 5c75bbccdb..b195d76a8e 100644
--- a/test/scripts/filters/backtick_code_block.js
+++ b/test/scripts/filters/backtick_code_block.js
@@ -650,5 +650,19 @@ describe('Backtick code block', () => {
codeBlock(data);
data.content.should.eql('' + expected + '');
});
+
+ it('handle empty code block', () => {
+ const data = {
+ content: [
+ '``` js',
+ '```',
+ '# New line',
+ '``` js',
+ '```'
+ ].join('\n')
+ };
+ codeBlock(data);
+ data.content.match(//g).length.should.eql(2);
+ });
});
});