Skip to content

Commit

Permalink
fix(backtick_code): handle empty code blocks (#5206)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed May 20, 2023
1 parent 725422a commit c62909d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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*(.+)?/;

Expand Down
14 changes: 14 additions & 0 deletions test/scripts/filters/backtick_code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,5 +650,19 @@ describe('Backtick code block', () => {
codeBlock(data);
data.content.should.eql('<hexoPostRenderCodeBlock>' + expected + '</hexoPostRenderCodeBlock>');
});

it('handle empty code block', () => {
const data = {
content: [
'``` js',
'```',
'# New line',
'``` js',
'```'
].join('\n')
};
codeBlock(data);
data.content.match(/<hexoPostRenderCodeBlock>/g).length.should.eql(2);
});
});
});

0 comments on commit c62909d

Please sign in to comment.