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: allow to add link with code block inside alias text part #558

Conversation

eh2077
Copy link
Contributor

@eh2077 eh2077 commented Jul 14, 2023

Fixed Issues

$ Expensify/App#22492
Proposal: Expensify/App#22492 (comment)

Tests

  1. Go to a chat and add following comment
[```code```](google.com)
  1. Verify that only code is displayed as code block and link google.com is displayed as auto link.
  2. Edit the comment and verify the initial draft is
[```
code
```
]([google.com](https://google.com))

Demo video

Screen.Recording.2023-07-14.at.5.47.33.PM.mov

QA

Same as test

@eh2077 eh2077 marked this pull request as ready for review July 15, 2023 14:46
@eh2077 eh2077 requested a review from a team as a code owner July 15, 2023 14:46
@melvin-bot melvin-bot bot requested review from pecanoro and removed request for a team July 15, 2023 14:47
@pecanoro pecanoro requested a review from a team July 17, 2023 17:44
@melvin-bot melvin-bot bot requested review from francoisl and removed request for a team July 17, 2023 17:44
@pecanoro pecanoro removed the request for review from francoisl July 17, 2023 17:44
@pecanoro
Copy link
Contributor

Ugh, I tried to assign PullerBear again to fix the assignment but i think I will have to assign manually the CME and C+

@pecanoro
Copy link
Contributor

@hayata-suenaga So the issue wasn't correctly linked in the PR so it failed to assign you, that means you won't get the extra contributions. I could either review it as well or unassign myself, but then, if I review it, I will get the contributions that you should be getting (it's only one though) so up to you.

@thesahindia
Copy link
Member

thesahindia commented Jul 17, 2023

I will test it in the morning. It's already EOD for me. Sorry for the delay on this one.

@hayata-suenaga hayata-suenaga requested review from hayata-suenaga and removed request for hayata-suenaga July 17, 2023 21:54
@hayata-suenaga
Copy link
Contributor

@pecanoro I'll keep myself assigned I don't care about contribution points so much so please review the PR. I'm not familiar with ExpensiMark so any extra eye is appreciated 🙇

@thesahindia
Copy link
Member

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (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
    • 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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
  • 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 reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web Screenshot 2023-07-18 at 3 36 46 PM
Mobile Web - Chrome Screenshot 2023-07-18 at 3 48 56 PM
Mobile Web - Safari Screenshot 2023-07-18 at 3 57 28 PM
Desktop Screenshot 2023-07-18 at 3 39 59 PM
iOS Screenshot 2023-07-18 at 3 56 35 PM
Android Screenshot 2023-07-18 at 3 54 07 PM

Copy link
Member

@thesahindia thesahindia left a comment

Choose a reason for hiding this comment

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

Tests well!

@@ -457,7 +457,7 @@ export default class ExpensiMark {
}
replacedText = replacedText.concat(textToCheck.substr(startIndex, (match.index - startIndex)));

if (abort) {
if (abort || match[1].includes('<pre>')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

does match[1] contains the strings captured by regex of capture group?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

why can we be sure that

 should be captured in the first capturing group?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hayata-suenaga That's an interesting question. The order of regex capturing group is determined by the regex expression, from left to right and from outer to inner. Eg, for regex

/(abc(d(e)))(fg)(hi)/gm
image

See also

const MARKDOWN_LINK_REGEX = new RegExp(`\\[([^\\][]*(?:\\[[^\\][]*][^\\][]*)*)]\\(${MARKDOWN_URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`, 'gi');

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Capturing_group

Copy link
Contributor

Choose a reason for hiding this comment

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

thank you for the detailed explanation @eh2077 that makes sense 👍

@parasharrajat
Copy link
Member

parasharrajat commented Jul 18, 2023

I think the real problem is that ``` is being parsed as code block but it should be online code block.

So either we should parse it as an inline code block or not parse it. IMO, the code block syntax should be.

` ` `
test
` ` `

There is another Expensify/App#23034 issue that is related inline syntax of the code block. I don't know why we allowed it to be parsed in an inline context.

Copy link
Contributor

@pecanoro pecanoro left a comment

Choose a reason for hiding this comment

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

Tested and working as expected!

@parasharrajat
Copy link
Member

Any thoughts on my comment #558 (comment) ?

@eh2077
Copy link
Contributor Author

eh2077 commented Jul 19, 2023

I think the real problem is that ``` is being parsed as code block but it should be online code block.

@parasharrajat Thanks for your comment. While I don’t agree with you about this. I think translating markdown code block syntax ``` to HTML block-level <pre> tag is a right choice. We use single backtick syntax for inline code block.

I think I misunderstood your point. You suggested to parse inline three backtick ``` syntax, like ```code```
to HTML inline <code> tag right? I think that makes sense from markdown rendering perspective but I have concerns to convert the inline HTML <code> tag to original markdown.

For example, markdown ```text``` is translated to html <code>text</code> and then the html will be translated into markdown `text` which is different from the original input.

@eh2077
Copy link
Contributor Author

eh2077 commented Jul 19, 2023

@parasharrajat This PR shouldn’t conflict with the direction to fix the issue you mentioned because the alias text part of link supports multiple line text, like

[
```
text
```
](google.com)

Copy link
Contributor

@hayata-suenaga hayata-suenaga left a comment

Choose a reason for hiding this comment

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

👍

@hayata-suenaga hayata-suenaga merged commit fea1a75 into Expensify:main Jul 19, 2023
@parasharrajat
Copy link
Member

For example, markdown text is translated to html text and then the html will be translated into markdown text which is different from the original input.

Good point @eh2077. In that case, we shouldn't allow pre formatting with inline syntax. ```code``` should be incorrect format. Correct should always be

` ` `
code
` ` `

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.

5 participants