-
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
convert html to flat text for LHN uses #440
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
recheck |
Co-authored-by: Rajat Parashar <parasharrajat@users.noreply.github.com>
Co-authored-by: Rajat Parashar <parasharrajat@users.noreply.github.com>
Co-authored-by: Rajat Parashar <parasharrajat@users.noreply.github.com>
const html = '1<br />2<br />3'; | ||
const text = '1 2 3'; | ||
|
||
expect(parser.htmlToFlatText(html)).toBe(text); |
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.
Shouldn't this be updated?
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.
Ahh yeah forgot about that, I'm on it.
Co-authored-by: Rajat Parashar <parasharrajat@users.noreply.github.com>
Any things I should update here? |
cc: @Luke9389 |
{ | ||
name: 'blockquote', | ||
regex: /<\/blockquote>/gm, | ||
replacement: ' ', |
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'm surprised the tests with blockquotes work, considering that the
const html = '<blockquote>Confusing stuff</blockquote>Tell me about it';
const text = 'Confusing stuff Tell me about it';
Why isn't there a space before the word "Confusing" 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.
Also, it seems we're only capturing the closing tag. I must be wrong about that though because the tests are passing.
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.
Why isn't there a space before the word "Confusing" here?
Also, it seems we're only capturing the closing tag. I must be wrong about that though because the tests are passing.
Here we loop the 3 rules
- replacing breakline with space
/((<br[^>]*>)+)/gi
- replacing blockquote with space
/<\/blockquote>/gm
. This the solution for the issue - strip all the tags left behind with an empty string
/(<([^>]+)>)/gi
this.htmlToTextRules.forEach((rule) => {
replacedText = replacedText.replace(rule.regex, rule.replacement);
});
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.
Ahh, ok, I see. I didn't realize we apply all rules in a row.
thanks for the explanation!
This PR caused a bug Expensify/App#17658. The html to text function should have also unescaped html entities e.g. |
@parasharrajat @Luke9389 will you please review this?
[Explanation of the change or anything fishy that is going on]
I'm adding a new function to replace the HTML report message that use for showing text on LHN.
Fixed Issues
$ Expensify/App#8134
Tests
__tests__/ExpensiMark-FlatText-test.js
Type above text and should be converted to text
Confusing stuff Tell me about it
QA
Verify that
__tests__/ExpensiMark-FlatText-test.js
is pass.The function created is used on showing the converted html last message on LHN.