Skip to content
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: unwanted linebreaks added when translating html blockquote to markdown #554

Conversation

eh2077
Copy link
Contributor

@eh2077 eh2077 commented Jun 28, 2023

Fixed Issues

$ Expensify/App#20725

Tests

  1. Go to a chat and add a comment for case 1
==== Case 1: simple quote ===
> one line quote a

> two line quote b
> two line quote b

> quote c with internal line break
> 
> quote c with internal line break
  1. Open the comment in editing mode and verify that the initial draft is same as input.

  2. Select the comment, copy the selection by Ctr/Cmd + C, paste it to composer and verify that it's same as input

    case-1.mov
  3. Add a comment for case 2

==== Case 2: quote surrounded by text ===
text a
> quote a

> quote b
text b

text c
> quote c
text c
  1. Repeat step 2 and 3

    case-2.mov
  2. Add a comment for case 3

==== Case 3: quote surrounded by inline element ===
_italic a_
> quote a

> quote b
*bold b*

_italic c_
> quote c
*bold c*
  1. Repeat step 2 and 3

    case-3.mov
  2. Open w3schools, add following html and run

<!DOCTYPE html>
<html>
<body>

<p>==== Case 4A: quote surrounded by block element ===</p>

<pre>code fence a</pre>
<blockquote>
quote a
</blockquote>

<br />

<blockquote>
quote b
</blockquote>
<pre>code fence b</pre>

<br />

<pre>code fence c</pre>
<blockquote>
quote c
</blockquote>
<pre>code fence c</pre>

</body>
</html>
  1. Select and copy html from right hand side of w3schools page and paste it to composer
  2. Verify that the composer input is equal to following input
==== Case 4A: quote surrounded by block element ===
```
code fence a
```
> quote a

> quote b
```
code fence b
```

```
code fence c
```
> quote c
```
code fence c
```
case-4a-w3c.mov
  1. Repeat Step 8 with following html
<!DOCTYPE html>
<html>
<body>

<p>==== Case 4B: quote surrounded by block element ===</p>

<h1>h1 a</h1>
<blockquote>
quote a
</blockquote>

<br />

<blockquote>
quote b
</blockquote>
<h1>h1 b</h1>

<br />

<h1>h1 c</h1>
<blockquote>
quote c
</blockquote>
<h1>h1 c</h1>

</body>
</html>
  1. Repeat step 9
  2. Verify that the composer input is equal to following input
==== Case 4B: quote surrounded by block element ===
# h1 a
> quote a

> quote b
# h1 b

# h1 c
> quote c
# h1 c
case-4b-w3c.mov

QA

  1. Go to a chat and add comment
==== Case 1: simple quote ===
> one line quote a

> two line quote b
> two line quote b

> quote c with internal line break
> 
> quote c with internal line break

==== Case 2: quote surrounded by text ===
text a
> quote a

> quote b
text b

text c
> quote c
text c

==== Case 3: quote surrounded by inline element ===
_italic a_
> quote a

> quote b
*bold b*

_italic c_
> quote c
*bold c*
  1. Open the comment in editing mode and verify that the initial draft is same as input.
  2. Test copy and pasting
    3a. On Web and Desktop, select the comment, copy the selection by Ctr/Cmd + C, paste it to composer and verify that it's same as input
    3b. On mobile, long press comment, copy to clipboard, pasting in composer and verify that it's same as input
  3. (Perform step 4-9 on Web only) Open w3schools, add following html and run
<!DOCTYPE html>
<html>
<body>

<p>==== Case 4A: quote surrounded by block element ===</p>

<pre>code fence a</pre>
<blockquote>
quote a
</blockquote>

<br />

<blockquote>
quote b
</blockquote>
<pre>code fence b</pre>

<br />

<pre>code fence c</pre>
<blockquote>
quote c
</blockquote>
<pre>code fence c</pre>

</body>
</html>
  1. Select and copy html from right hand side of w3schools page and paste it to composer
  2. Verify that the composer input is equal to following input
==== Case 4A: quote surrounded by block element ===
```
code fence a
```
> quote a

> quote b
```
code fence b
```

```
code fence c
```
> quote c
```
code fence c
```
case-4a-w3c.mov
  1. Repeat Step 4 with following html
<!DOCTYPE html>
<html>
<body>

<p>==== Case 4B: quote surrounded by block element ===</p>

<h1>h1 a</h1>
<blockquote>
quote a
</blockquote>

<br />

<blockquote>
quote b
</blockquote>
<h1>h1 b</h1>

<br />

<h1>h1 c</h1>
<blockquote>
quote c
</blockquote>
<h1>h1 c</h1>

</body>
</html>
  1. Repeat step 5
  2. Verify that the composer input is equal to following input
==== Case 4B: quote surrounded by block element ===
# h1 a
> quote a

> quote b
# h1 b

# h1 c
> quote c
# h1 c
case-4b-w3c.mov

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
web.mov
case-4a-w3c.mov
case-4b-w3c.mov
Mobile Web - Chrome
mobile-chrome.mp4
Mobile Web - Safari
mobile-safari.mp4
Desktop
desktop.mov
iOS
ios.mp4
Android
android.mp4

@eh2077 eh2077 requested a review from a team as a code owner June 28, 2023 03:00
@melvin-bot melvin-bot bot requested review from MonilBhavsar and removed request for a team June 28, 2023 03:01
@eh2077
Copy link
Contributor Author

eh2077 commented Jun 28, 2023

When preparing the PR, I performed testing by checking quote surrounded by text, inline and block elements. I found that currently we have 3 types of block elements(<h1>, <blockquote> and <pre>). I found that the way that the library handle line break for <pre> tag is really twisted and tricky. So, I temporarily use w3schools page to complete the test case.

During the testing

  1. I found a bug that heading after a quote is not rendered, which is also reproducible on production. So I reported a bug on Slack.
  2. I tried to refrain changing things outside the scope of this issue. So, I just corrected test cases of quote and add new test case to better cover the fix.
  3. I confirmed that below two tests aren’t regression from this fix. They're existing on the production as well. I did try to get them fixed but they're both tricky.
case-4a.mov
case-4b.mov

@@ -654,9 +656,6 @@ export default class ExpensiMark {
if (textToFormat !== '') {
replacedText += this.formatTextForQuote(regex, textToFormat, replacement);
}

// Replace all the blank lines between quotes, if there are only blank lines between them
replacedText = replacedText.replace(/(<\/blockquote>((\s*)+)<blockquote>)/g, '</blockquote><blockquote>');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's safe to remove this as it's not covered by any unit test.
I think we should retain line breaks between quotes because the App prefers to display user's input as it is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm can you look into when it was added and why please?

Copy link
Contributor Author

@eh2077 eh2077 Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iwiznia The change was added in this PR #385 which is quite old. This change was included at that time but no unit test case was added together in PR #385. From the corresponding original issue Expensify/App#2670, I found that it fixed retaining only one empty line within a quote if there’re more than one. But later we wanted to retain all empty rows inside a quote, see slack discussion https://expensify.slack.com/archives/C01GTK53T8Q/p1682331970891359.

I have fixed another issue #531 to avoid removing line break before and after heading. The App has been reported many issues about line break handling. And I found that we prefer to keep line breaks from user's input as it is instead of removing them, which is different from markdown rendering on Github.

So, I think, in this case, we can also remove it to keep line breaks between quotes. Strictly speaking, it can be out of the scope of this issue but given it's annoying when performing tests and is easy to fix without breaking existing tests, I prefer to fix it and add tests to cover it together in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Friendly bump @iwiznia

@eh2077
Copy link
Contributor Author

eh2077 commented Jun 28, 2023

@iwiznia @narefyev91 I'm happy to hear your thoughts on this to move this issue forward.

@narefyev91
Copy link

@eh2077 can you please following standard template to contributor PR. Also if issue already exists in production and not related to current one - we can skip it here. The main idea to fix current issue and not produce any regressions

@MonilBhavsar
Copy link
Contributor

Ionatan could you please also review as I think you have more context on the issue

@eh2077
Copy link
Contributor Author

eh2077 commented Jun 29, 2023

@eh2077 can you please following standard template to contributor PR. Also if issue already exists in production and not related to current one - we can skip it here. The main idea to fix current issue and not produce any regressions

Got it. I'm going to test case 1, 2 and 3 on all platforms and case 4A and 4B on web only.

@eh2077
Copy link
Contributor Author

eh2077 commented Jun 29, 2023

@narefyev91 Updated PR check list

@eh2077
Copy link
Contributor Author

eh2077 commented Jul 3, 2023

Bump @narefyev91

Copy link

@narefyev91 narefyev91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@eh2077
Copy link
Contributor Author

eh2077 commented Jul 4, 2023

@MonilBhavsar Can you help to merge this PR if you're also happy with the change?

cc @iwiznia

Copy link
Contributor

@MonilBhavsar MonilBhavsar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding detailed testing steps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants