Skip to content

Commit

Permalink
Merge pull request #782 from bernhardoj/fix/autolink-doesnt-work-if-p…
Browse files Browse the repository at this point in the history
…laced-before-img
  • Loading branch information
dangrous authored Aug 19, 2024
2 parents 18f8ace + 8a6a696 commit e89eff9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2137,9 +2137,9 @@ describe('Image markdown conversion to html tag', () => {
});

test('Text containing image and autolink', () => {
const testString = 'An image of a banana: ![banana](https://example.com/banana.png) an autolink: example.com';
const testString = 'An autolink: example.com before an image of a banana: ![banana](https://example.com/banana.png), another autolink: example.com after the image';
const resultString =
'An image of a banana: <img src="https://example.com/banana.png" alt="banana" /> an autolink: <a href="https://example.com" target="_blank" rel="noreferrer noopener">example.com</a>';
'An autolink: <a href="https://example.com" target="_blank" rel="noreferrer noopener">example.com</a> before an image of a banana: <img src="https://example.com/banana.png" alt="banana" />, another autolink: <a href="https://example.com" target="_blank" rel="noreferrer noopener">example.com</a> after the image';
expect(parser.replace(testString)).toBe(resultString);
});

Expand Down
2 changes: 1 addition & 1 deletion lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export default class ExpensiMark {
name: 'autolink',

process: (textToProcess, replacement) => {
const regex = new RegExp(`(?![^<]*>|[^<>]*<\\/(?!h1>))([_*~]*?)${UrlPatterns.MARKDOWN_URL_REGEX}\\1(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>|.+\\/>))`, 'gi');
const regex = new RegExp(`(?![^<]*>|[^<>]*<\\/(?!h1>))([_*~]*?)${UrlPatterns.MARKDOWN_URL_REGEX}\\1(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>))`, 'gi');
return this.modifyTextForUrlLinks(regex, textToProcess, replacement as ReplacementFn);
},

Expand Down

0 comments on commit e89eff9

Please sign in to comment.