-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow emoji as link text #749
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -295,21 +295,21 @@ test('Test markdown replacement for invalid emails', () => { | |||||||||
|
||||||||||
test('Test markdown replacement for emojis with emails', () => { | ||||||||||
const testString = | ||||||||||
'Do not replace the emoji with link ' + | ||||||||||
'Replace the emoji with link ' + | ||||||||||
'[😄](abc@gmail.com) ' + | ||||||||||
'[😄]( abc@gmail.com) ' + | ||||||||||
'[😄] abc@gmail.com ' + | ||||||||||
'[😄]((abc@gmail.com)) ' + | ||||||||||
'[😄abc@gmail.com](abc@gmail.com) ' + | ||||||||||
'[😄 abc@gmail.com ](abc@gmail.com) '; | ||||||||||
const result = | ||||||||||
'Do not replace the emoji with link ' + | ||||||||||
'[<emoji>😄</emoji>](<a href="mailto:abc@gmail.com">abc@gmail.com</a>) ' + | ||||||||||
'Replace the emoji with link ' + | ||||||||||
'<a href=\"mailto:abc@gmail.com\"><emoji>😄</emoji></a> ' + | ||||||||||
'[<emoji>😄</emoji>]( <a href="mailto:abc@gmail.com">abc@gmail.com</a>) ' + | ||||||||||
'[<emoji>😄</emoji>] <a href="mailto:abc@gmail.com">abc@gmail.com</a> ' + | ||||||||||
'[<emoji>😄</emoji>]((<a href="mailto:abc@gmail.com">abc@gmail.com</a>)) ' + | ||||||||||
'[<emoji>😄</emoji><a href="mailto:abc@gmail.com">abc@gmail.com</a>](<a href="mailto:abc@gmail.com">abc@gmail.com</a>) ' + | ||||||||||
'[<emoji>😄</emoji> <a href="mailto:abc@gmail.com">abc@gmail.com</a> ](<a href="mailto:abc@gmail.com">abc@gmail.com</a>) '; | ||||||||||
'<a href="mailto:abc@gmail.com"><emoji>😄</emoji>abc@gmail.com</a> ' + | ||||||||||
'<a href="mailto:abc@gmail.com"><emoji>😄</emoji> abc@gmail.com</a> '; | ||||||||||
expect(parser.replace(testString)).toBe(result); | ||||||||||
}); | ||||||||||
|
||||||||||
|
@@ -1198,9 +1198,10 @@ test('Test for link with no content', () => { | |||||||||
expect(parser.replace(testString)).toBe(resultString); | ||||||||||
}); | ||||||||||
|
||||||||||
// Replace the emoji with email link | ||||||||||
test('Test for link with emoji', () => { | ||||||||||
const testString = '[😀](www.link.com)'; | ||||||||||
const resultString = '[<emoji>😀</emoji>](<a href="https://www.link.com" target="_blank" rel="noreferrer noopener">www.link.com</a>)'; | ||||||||||
const resultString = '<a href="https://www.link.com" target="_blank" rel="noreferrer noopener"><emoji>😀</emoji></a>'; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
expect(parser.replace(testString)).toBe(resultString); | ||||||||||
}); | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,7 +173,7 @@ export default class ExpensiMark { | |
return this.modifyTextForEmailLinks(regex, textToProcess, replacement as ReplacementFn, shouldKeepRawInput); | ||
}, | ||
replacement: (_extras, match, g1, g2) => { | ||
if (g1.match(Constants.CONST.REG_EXP.EMOJIS) || !g1.trim()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
if (!g1.trim()) { | ||
return match; | ||
} | ||
const label = g1.trim(); | ||
|
@@ -182,7 +182,7 @@ export default class ExpensiMark { | |
return `<a href="${href}">${formattedLabel}</a>`; | ||
}, | ||
rawInputReplacement: (_extras, match, g1, g2, g3) => { | ||
if (g1.match(Constants.CONST.REG_EXP.EMOJIS) || !g1.trim()) { | ||
if (!g1.trim()) { | ||
return match; | ||
} | ||
|
||
|
@@ -249,13 +249,13 @@ export default class ExpensiMark { | |
name: 'link', | ||
process: (textToProcess, replacement) => this.modifyTextForUrlLinks(MARKDOWN_LINK_REGEX, textToProcess, replacement as ReplacementFn), | ||
replacement: (_extras, match, g1, g2) => { | ||
if (g1.match(Constants.CONST.REG_EXP.EMOJIS) || !g1.trim()) { | ||
if (!g1.trim()) { | ||
return match; | ||
} | ||
return `<a href="${Str.sanitizeURL(g2)}" target="_blank" rel="noreferrer noopener">${g1.trim()}</a>`; | ||
}, | ||
rawInputReplacement: (_extras, match, g1, g2) => { | ||
if (g1.match(Constants.CONST.REG_EXP.EMOJIS) || !g1.trim()) { | ||
if (!g1.trim()) { | ||
return match; | ||
} | ||
return `<a href="${Str.sanitizeURL(g2)}" data-raw-href="${g2}" data-link-variant="labeled" target="_blank" rel="noreferrer noopener">${g1.trim()}</a>`; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added as comment