-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
13 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -470,29 +470,31 @@ export default class ExpensiMark { | |
} | ||
replacedText = replacedText.concat(textToCheck.substr(startIndex, (match.index - startIndex))); | ||
|
||
// We want to avoid matching domains in email addresses so we don't render them as URLs. | ||
// If the matched Url has a leading @ sign, The Url's domain can be a domain of email address. | ||
// At this case, The matched string should not be parsed as Url, | ||
// But it can contain another Url which should be parsed. (e.g. [email protected]/https://www.test.com) | ||
// So We will retry to apply autolink rule to the string(e.g. /https://www.test.com) except for domain(e.g. expensify.com) after @ sign. | ||
let abort = false; | ||
let isReparsedByAutolink = false; | ||
// We want to avoid matching domains in email addresses so we don't render them as URLs, | ||
// but we need to check if there are valid URLs after the email address and render them accordingly, | ||
// e.g. [email protected]/https://www.test.com | ||
let isDoneMatching = false; | ||
let shouldApplyAutoLinkAgain = true; | ||
|
||
// If we find a URL with a leading @ sign, we need look for other domains in the rest of the string | ||
if ((match.index !== 0) && (textToCheck[match.index - 1] === '@')) { | ||
const domainRegex = new RegExp('^(([a-z-0-9]+\\.)+[a-z]{2,})(\\S*)', 'i'); | ||
const domainMatch = domainRegex.exec(match[2]); | ||
|
||
// If we find another domain in the remainder of the string, we apply the auto link rule again and set a flag to avoid re-doing below. | ||
if ((domainMatch !== null) && (domainMatch[3] !== '')) { | ||
isReparsedByAutolink = true; | ||
replacedText = replacedText.concat(domainMatch[1] + this.replace(domainMatch[3], {filterRules: ['autolink']})); | ||
shouldApplyAutoLinkAgain = false; | ||
} else { | ||
abort = true; | ||
// Otherwise, we're done applying rules | ||
isDoneMatching = true; | ||
} | ||
} | ||
|
||
if (abort || match[1].includes('<pre>')) { | ||
// We don't want to apply link rule if match[1] contains the code block inside the [] of the markdown e.g. [```example```](https://example.com) | ||
if (isDoneMatching || match[1].includes('<pre>')) { | ||
replacedText = replacedText.concat(textToCheck.substr(match.index, (match[0].length))); | ||
} else if (!isReparsedByAutolink) { | ||
} else if (shouldApplyAutoLinkAgain) { | ||
const urlRegex = new RegExp(`^${LOOSE_URL_REGEX}$|^${URL_REGEX}$`, 'i'); | ||
|
||
// `match[1]` contains the text inside the [] of the markdown e.g. [example](https://example.com) | ||
|