-
Notifications
You must be signed in to change notification settings - Fork 135
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
Fix new lines when replacing <blockquote> and <br /> #474
Fix new lines when replacing <blockquote> and <br /> #474
Conversation
cc @mollfpr since you added this code that transform html into text using regexes. Just tagging you in case you notice that what I'm doing here will cause a bug. |
@@ -287,7 +287,7 @@ export default class ExpensiMark { | |||
this.htmlToTextRules = [ | |||
{ | |||
name: 'breakline', | |||
regex: /((<br[^>]*>)+)/gi, | |||
regex: /<br[^>]*>/gi, |
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 just roll back to the issue and the PR. Back then the issue is about the last message text in the LHN when sending a blockquote. So the solution I propose is to replace the blockquote closing tag with a space. Other regex rules in the htmlToText
rule from the E/App that I move to expensi-mark.
I believe this will affect the text in LHN where it should be replacing adjoin break lines with a space.
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.
@mollfpr I tested blockquotes but couldn't spot any new bugs. Did you find any issues with these changes?
I did notice that entering two block quotes with empty new lines seems to remove the space in the LHN message, but that's also happening on staging so it's not introduced here.
web.mov
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.
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 guess we should separate the function to convert the message HTML to text between LHN and chat.
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, something like that... I was looking at the backend, and convert the html
to lastMessageText
using a function that applies the same regexes that htmlToText
apply, including /((<br[^>]*>)+)/
.
I was thinking that it doesn't make much sense that 🥶.<br /><br /><br />🥶
gets converted to 🥶..🥶
(two spaces) just collapsing the <br />
into a single space... why the result is not 🥶.🥶
(single space) if our intention is really to collapse multiple white spaces. I'm thinking that htmlToText
should maybe be changed to:
- Step 1: replace each
<br />
by single spaces - Step 2: collapse all consecutive spaces into a single space
I still have to look at what the back end is doing to produce the text
of the message in the report action from the html
. Is there a reason why we don't collapse the spaces when deriving text
from html
?
btw, I replaced the whitespaces in 🥶 🥶
by .
because they are getting collapsed here.
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.
I guess we should separate the function to convert the message HTML to text between LHN and chat.
@mollfpr so.. I think the best way to go here is:
htmlToText
won't collapse multiple<br />
into a single whitespace because that is only needed for thelastMessageText
which is used in the LHN (what this PR is doing)- The function ReportUtils.formatReportLastMessageText will have the responsibility of collapsing consecutive whitespaces into a single one. We already use this function to process what we put in
lastMessageText
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.
@aldo-expensify sounds good to me!
I found an issue when testing this PR, but it's not related to the PR changes. The last message on LHN flinched without whitespace when sending a text with a blockquote.
Screen.Recording.2022-11-27.at.22.16.53.mov
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.
Logged issue here https://expensify.slack.com/archives/C049HHMV9SM/p1669564594408699
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 just waiting on @mollfpr confirmation on any new issues with blockquotes
…o_replace-each-br-for-single-whitespace
@mollfpr @luacmartins can you review from 0 again 🙏 ? I changed this PR to:
|
Will test in a couple of hours. |
Sorry, I have a question I'm a little bit confused. Is this PR will fix Expensify/App#12894 and Expensify/App#11494? Anyway, the changes look much better now 👍 |
Partially, there is also a PR for the API and also for the App. This PR:
Other PRs:
|
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!
This is part of a group of changes to preserving new lines when converting from
message[0].html
usingExpensiMark.htmlToText
. This should improve:<blockquote>
cause buggy spacing)Fixed Issues
$ Expensify/App#12894 (partially)
Expensify/App#11494 (partially)
Tests
Make sure unit test run (
npm run test
)\n
inmessage[0].text
message[0].text
containsbefore quotes\nquoted text\nafter quotes
. This is because<blockquote>
are block elements and they should cause line breaks in the content.QA
\n
inmessage[0].text
message[0].text
containsbefore quotes\nquoted text\nafter quotes
. This is because<blockquote>
are block elements and they should cause line breaks in the content.