Skip to content

Commit

Permalink
Merge pull request #750 from skyweb331/main
Browse files Browse the repository at this point in the history
fix parsing markdown for multiline email hyperlink
  • Loading branch information
marcochavezf committed Jul 15, 2024
2 parents 1344a32 + 034bac8 commit d547933
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,24 @@ test('Test markdown replacement for emails wrapped in bold/strikethrough/italic
expect(parser.replace(testInput)).toBe(result);
});

test('Test markdown replacement for multiline email hyperlinks', () => {
let testInput = '[test\ntest](test@test.com)';
let result = '<a href="mailto:test@test.com">test<br />test</a>';
expect(parser.replace(testInput)).toBe(result);

testInput = '[test\n\n\n](test@test.com)';
result = '<a href="mailto:test@test.com">test</a>';
expect(parser.replace(testInput)).toBe(result);

testInput = '[test\ntest](test.com)';
result = '<a href="https://test.com" target="_blank" rel="noreferrer noopener">test<br />test</a>';
expect(parser.replace(testInput)).toBe(result);

testInput = 'test@gmail.com';
result = '<a href="mailto:test@gmail.com">test@gmail.com</a>';
expect(parser.replace(testInput)).toBe(result);
});

// Check emails within other markdown
test('Test emails within other markdown', () => {
const testString =
Expand Down
4 changes: 4 additions & 0 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,10 @@ export default class ExpensiMark {
replacedText = replacedText.concat(replacedMatch);
startIndex = match.index + match[0].length;

// Line breaks (`\n`) followed by empty contents are already removed
// but line breaks inside contents should be parsed to <br/> to skip `autoEmail` rule
replacedText = this.replace(replacedText, {filterRules: ['newline'], shouldEscapeText: false});

// Now we move to the next match that the js regex found in the text
match = regex.exec(textToCheck);
}
Expand Down

0 comments on commit d547933

Please sign in to comment.