Skip to content

Commit

Permalink
Merge pull request #401 from mananjadhav/fix/md-hyperlink-regex
Browse files Browse the repository at this point in the history
Fixed characters support between [] for Hyperlinks
  • Loading branch information
stitesExpensify authored Jul 28, 2021
2 parents 7d8408c + b4ed44f commit e83c699
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,12 @@ test('Test markdown and url links with inconsistent starting and closing parens'
+ '(http://foo.com/(something)?after=parens) '
+ '(((http://foo.com/(something)?after=parens '
+ '(((http://foo.com/(something)?after=parens))) '
+ 'http://foo.com/(something)?after=parens))) ';
+ 'http://foo.com/(something)?after=parens))) '
+ '[Yo (click here to see a cool cat)](https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg) '
+ '[Yo click here to see a cool cat)](https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg) '
+ '[Yo (click here to see a cool cat](https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg) '
+ '[Yo click * $ & here to see a cool cat](https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg) ';


const resultString = '<a href="http://google.com/(something)?after=parens" target="_blank">google</a> '
+ '(<a href="http://google.com/(something)?after=parens" target="_blank">google</a>) '
Expand All @@ -344,7 +349,12 @@ test('Test markdown and url links with inconsistent starting and closing parens'
+ '(<a href="http://foo.com/(something)?after=parens" target="_blank">http://foo.com/(something)?after=parens</a>) '
+ '(((<a href="http://foo.com/(something)?after=parens" target="_blank">http://foo.com/(something)?after=parens</a> '
+ '(((<a href="http://foo.com/(something)?after=parens" target="_blank">http://foo.com/(something)?after=parens</a>))) '
+ '<a href="http://foo.com/(something)?after=parens" target="_blank">http://foo.com/(something)?after=parens</a>))) ';
+ '<a href="http://foo.com/(something)?after=parens" target="_blank">http://foo.com/(something)?after=parens</a>))) '
+ '<a href="https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg" target="_blank">Yo (click here to see a cool cat)</a> '
+ '<a href="https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg" target="_blank">Yo click here to see a cool cat)</a> '
+ '<a href="https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg" target="_blank">Yo (click here to see a cool cat</a> '
+ '<a href="https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg" target="_blank">Yo click * $ &amp; here to see a cool cat</a> ';


expect(parser.replace(testString)).toBe(resultString);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class ExpensiMark {

process: (textToProcess, replacement) => {
const regex = new RegExp(
`\\[((?:[\\w\\s\\d!?&#;:\\/\\-\\.\\+=<>,@\\[\\]‘’“”]|(?:<code>.+<\\/code>))+)\\]\\(${URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`,
`\\[(.+?)\\]\\(${URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`,
'gi'
);
return this.modifyTextForUrlLinks(regex, textToProcess, replacement);
Expand Down

0 comments on commit e83c699

Please sign in to comment.