-
Notifications
You must be signed in to change notification settings - Fork 137
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
Update regex of italic #526
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
recheck |
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.
- Please add more tests for multiline syntax.
- Add unit tests for the new changes to the regex.
Do you think we should also update the bold regex?
@parasharrajat Thanks so much for your reminder. I just updated, please help to check again |
@alex-mechler can you please trigger checks? |
@dukenv0307 I will suggest that you create the PR on the Expensify/APP repo and use the latest commit hash from this PR. We can test it meanwhile this is being reviewed and merged. Once this is merged, we can update the hash there and close that as well. This will speed up the process. |
@parasharrajat The PR in App repo is ready |
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.
LGTM.
lib/ExpensiMark.js
Outdated
@@ -139,8 +139,8 @@ export default class ExpensiMark { | |||
* Use [\s\S]* instead of .* to match newline | |||
*/ | |||
name: 'italic', | |||
regex: /(?!_blank")\b_((?!\s)[\s\S]*?\S)_\b(?![^<]*(<\/pre>|<\/code>|<\/a>|_blank))/g, | |||
replacement: (match, g1) => (g1.includes('<pre>') ? match : `<em>${g1}</em>`), | |||
regex: /(?!_blank")([^\W_]?)_((?![\s_])[\s\S]*?[^\s_])_(?![^\W_])(?![^<]*(<\/pre>|<\/code>|<\/a>|_blank))/g, |
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.
I don't think we need this capture group here. We aren't doing anything with the captured characters, and it would let us avoid changing the replacement
. The test suite passes locally, and it captures the same test strings mentioned in the issue without this group
regex: /(?!_blank")([^\W_]?)_((?![\s_])[\s\S]*?[^\s_])_(?![^\W_])(?![^<]*(<\/pre>|<\/code>|<\/a>|_blank))/g, | |
regex: /(?!_blank")[^\W_]?_((?![\s_])[\s\S]*?[^\s_])_(?![^\W_])(?![^<]*(<\/pre>|<\/code>|<\/a>|_blank))/g, |
@alex-mechler I updated and tested again, it works well. Also updated new hash in App repo. Please help to check again. |
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.
LGTM and tested well, thanks for the quick updates!
Going to merge this since @parasharrajat had already approved |
Details
When entering ___ (3 underscores), the italic characters (underscores) got parsed and only leave one underscore after parsed.
It has 3 changes compared to the current italic regex we're using:
Replace
(?!\s)
by(?![\s_])
, so that it doesn't match _ at the beginning of the contentReplace
\S
by[^\s_]
, so that it doesn't match _ at the end of the contentReplace the word boundary \b by a regex at the beginning and end
([^\W_]?)
and(?![^\W_])
so that the word boundary will also exclude the _ as word, so that cases like content and content will work correctly.Also we need to update this replacement so that it will not replace if the match starts with a word character (this logic works with
([^\W_]?))
Fixed Issues
$ Expensify/App#17665
PROPOSAL: Expensify/App#17665 (comment)
Tests
To test, we need to update the hash commit of expensify-common package in App repo into
6a781aa8f027d87f78e5dd808759795631fc30e5
like this:"expensify-common": "git+ssh://git@github.com/Expensify/expensifycommon.git#6a781aa8f027d87f78e5dd808759795631fc30e5"
Open any chat and send these messages and verify that
___
--> Verify that this message isn't parsed_italic__
--> Verify that this message is parsed__italic_
--> Verify that this message is parsed_italic_another_italic_
--> Verify that this message is parsed_italic_
--> Verify that this message is parseds_italic
--> Verify that this message isn't parseditalic_s
--> Verify that this message isn't parsed--> Verify that this message is parsed
9.
--> Verify that this message isn't parsed
10.
--> Verify that this message isn't parsed
Offline tests
QA Steps
___
--> Verify that this message isn't parsed_italic__
--> Verify that this message is parsed__italic_
--> Verify that this message is parsed_italic_another_italic_
--> Verify that this message is parsed_italic_
--> Verify that this message is parseds_italic
--> Verify that this message isn't parseditalic_s
--> Verify that this message isn't parsedScreenshots/Videos
Web
Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Android