-
Notifications
You must be signed in to change notification settings - Fork 138
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
Add handling short mentions tags to ExpensiMark #824
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 |
---|---|---|
|
@@ -365,7 +365,7 @@ export default class ExpensiMark { | |
{ | ||
name: 'userMentions', | ||
regex: new RegExp( | ||
`(@here|[a-zA-Z0-9.!$%&+=?^\`{|}-]?)(@${Constants.CONST.REG_EXP.EMAIL_PART}|@${Constants.CONST.REG_EXP.PHONE_PART})(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>))`, | ||
`${Constants.CONST.REG_EXP.PRE_MENTION_TEXT_PART}(@${Constants.CONST.REG_EXP.EMAIL_PART}|@${Constants.CONST.REG_EXP.PHONE_PART})(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>))`, | ||
'gim', | ||
), | ||
replacement: (_extras, match, g1, g2) => { | ||
|
@@ -484,6 +484,41 @@ export default class ExpensiMark { | |
rawInputReplacement: '$1<a href="mailto:$2" data-raw-href="$2" data-link-variant="auto">$2</a>', | ||
}, | ||
|
||
/** | ||
* This regex matches a short user mention in a string. | ||
* A short-mention is a string that starts with the '@' symbol and is followed by a valid user's primary login without the email domain part | ||
* Ex: @john.doe, @user12345, but NOT @user@email.com | ||
* | ||
* Notes: | ||
* Phone is not a valid short mention. | ||
* In reality these "short-mentions" are just possible candidates, because the parser has no way of verifying if there exists a user named ex: @john.examplename. | ||
* The actual verification whether these mentions are pointing to real users is done in specific projects using ExpensiMark. | ||
* Nevertheless, "@john.examplename" is a correct possible short-mention, and so would be parsed. | ||
* This behaviour is similar to treating every user@something as valid user login. | ||
* | ||
* This regex will correctly preserve any @here mentions, the same way as "userMention" rule. | ||
*/ | ||
{ | ||
name: 'shortMentions', | ||
|
||
regex: new RegExp( | ||
`${Constants.CONST.REG_EXP.PRE_MENTION_TEXT_PART}(@(?=((?=[\\w]+[\\w'#%+-]+(?:\\.[\\w'#%+-]+)*)[\\w\\.'#%+-]{1,64}(?= |_|\\b))(?!([:\\/\\\\]))(?<end>.*))(?!here)\\S{3,254}(?=\\k<end>$))(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>|<\\/mention-user>|<\\/mention-here>))`, | ||
'gim', | ||
), | ||
replacement: (_extras, match, g1, g2) => { | ||
if (!Str.isValidMention(match)) { | ||
return match; | ||
} | ||
return `${g1}<mention-short>${g2}</mention-short>`; | ||
}, | ||
}, | ||
|
||
{ | ||
name: 'hereMentionAfterShortMentions', | ||
regex: /(<\/mention-short>)(@here)(?=\b)/gm, | ||
replacement: '$1<mention-here>$2</mention-here>', | ||
}, | ||
Comment on lines
+516
to
+520
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. @Kicu Is this still needed? Since patch does not have this code and it works fine for me. 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. 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. you should be able to test by yourself, you can just copy-paste this block and add it to the same file that patch modifies 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. @Kicu One improvement note: Add some border radius so that we know these are separate mentions in RN Live Markdown. 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. Adding rounded borders is quite a complicated feature on which we are already working, and for now we cannot implement it for native, only for web. In short: for now we can have it only on web, and a colleague is working on this. So I won't be touching styles in this PR |
||
|
||
{ | ||
// Use \B in this case because \b doesn't match * or ~. | ||
// \B will match everything that \b doesn't, so it works | ||
|
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.
This might be invalid emails after all. See https://stackoverflow.com/questions/12355858/how-many-symbol-can-be-in-an-email-address
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.
yeah indeed
test+1@gmail.com@gmail.com
looks like invalid email.But I thought the reasoning was that the parser should treat it as a separate email (1st part) and then just text
@gmail.com
which now becomes a short mention.Do you want me to change anything related to this?
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.
No.