Skip to content

Commit

Permalink
fix(codeblock): match whitespace but not newlines (#4625)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang authored Jan 29, 2021
1 parent de8814c commit 8075ed5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
This issue has been automatically marked as stale because lack of
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
exempt-issue-labels: bug,discussion,"help wanted",need-verify,need-investigation,pending-reply,proposal,feature-request,enhancement,documentation
exempt-issue-labels: bug,discussion,help wanted,need-verify,need-investigation,pending-reply,proposal,feature-request,enhancement,documentation
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

let highlight, prismHighlight;

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?(\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
17 changes: 17 additions & 0 deletions test/scripts/filters/backtick_code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,23 @@ describe('Backtick code block', () => {
codeBlock(data);
data.content.should.not.contain('`');
});

// test for Issue #4573
it('ignore trailing spaces but not newlines', () => {
const data = {
content: [
'``` js',
code,
'```',
'',
'# New line'
].join('\n')
};

codeBlock(data);
console.log(data.content);
data.content.should.contain('\n\n# New line');
});
});

describe('prismjs', () => {
Expand Down

0 comments on commit 8075ed5

Please sign in to comment.