Skip to content

Commit

Permalink
Fix strikethrough link is not parsed correctly on link with URL that …
Browse files Browse the repository at this point in the history
…contains tilde
  • Loading branch information
ZhenjaHorbach committed Sep 26, 2023
1 parent 8bcd790 commit 8e79ca9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1366,3 +1366,11 @@ test('Test strikethrough with multiple tilde characters', () => {
testString = '~~~~';
expect(parser.replace(testString)).toBe('~~~~');
});

test('Test strikethrough with link with URL that contains tilde', () => {
let testString = '~[Example Link](https://example.com/?example=~ex)~';
expect(parser.replace(testString)).toBe('<del><a href="https://example.com/?example=~ex" target="_blank" rel="noreferrer noopener">Example Link</a></del>');

testString = '~[Example Link](https://example.com/?~example=~~~ex~)~';
expect(parser.replace(testString)).toBe('<del><a href="https://example.com/?~example=~~~ex~" target="_blank" rel="noreferrer noopener">Example Link</a></del>');
});
2 changes: 1 addition & 1 deletion lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default class ExpensiMark {
},
{
name: 'strikethrough',
regex: /\B~((?=\S)(([^\s~]|\s(?!~))+?))~\B(?![^<]*(<\/pre>|<\/code>|<\/a>))/g,
regex: /\B~((?![\s~])[\s\S]*?[^\s~])~\B(?![^<]*(<\/pre>|<\/code>|<\/a>))/g,
replacement: (match, g1) => (this.containsNonPairTag(g1) ? match : `<del>${g1}</del>`),
},
{
Expand Down

0 comments on commit 8e79ca9

Please sign in to comment.