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

Live Markdown Preview #34292

Merged

Conversation

tomekzaw
Copy link
Contributor

@tomekzaw tomekzaw commented Jan 10, 2024

Details

This PR adds Live Markdown Preview feature using @expensify/react-native-live-markdown library (which is not open-sourced yet). Currently, the feature targets Android and iOS, but we are already working on Web support.

Fixed Issues

$ #27977
$ #32626
PROPOSAL:

Tests

Testing Replacement Rules

Code Fence:
Type: ```your text```
Expected: Text appears in a separate block formatted as code.

Inline Code Block:
Type: ``your text``
Expected: Text appears inline, formatted as code.

Email Link:
Type: test@email.com
Expected: Email address turns into a clickable mailto link.

URL Link:
Type: https://github.com/Expensify/App/pull/34292
Expected: Displays "#34292" as a clickable web link.

Italics
Type: _your text_
Expected: Text appears in italics.

Bold Text:
Type: *your text*
Expected: Text appears in bold.

Strikethrough Text:
Type: ~your text~
Expected: Text appears with a strikethrough.

Block Quote:
Type: > your text
Expected: Text appears as a block quote.

Heading:
Type: # Your Heading
Expected: Text appears as a large, bold heading.

Offline tests

QA Steps

  • Verify that no errors appear in the JS console

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: mWeb Chrome
    • iOS: Native
    • iOS: mWeb 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 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(theme.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 the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • 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.

Screenshots/Videos

Android: Native
android.mp4
Android: mWeb Chrome
iOS: Native
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-31.at.22.21.25.mp4
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop

This comment has been minimized.

@thienlnam
Copy link
Contributor

thienlnam commented Jan 11, 2024

I'm running into this pod install error

[!] Invalid `Podfile` file: cannot load such file -- /Users/jack/Expensidev/App/node_modules/react-native/scripts/react_native_pods.rb

 #  from /Users/jack/Expensidev/App/ios/Podfile:8
 #  -------------------------------------------
 #    # Resolve script with node to allow for hoisting
 >    require Pod::Executable.execute_command('node', ['-p',
 #      "require.resolve(
 #  -------------------------------------------

@tomekzaw
Copy link
Contributor Author

@thienlnam Do you have node_modules installed?

@thienlnam
Copy link
Contributor

I do, I've tried removing it and re-installing it but still no dice.
Let's see if @c3024 @shubham1206agra have better luck

@shubham1206agra
Copy link
Contributor

Screenshot 2024-01-11 at 10 08 56 PM

I want to make a design recommendation. Maybe we can adapt the design of live markdown shown here of link and quotes.
Right now, quotes have both standing line and > present. Maybe adapt from this design and use a lighter font tone to represent quotes.

@c3024
Copy link
Contributor

c3024 commented Jan 11, 2024

Screenshot 2024-01-11 at 10 56 54 PM

For code blocks the markdown is not quite the same as a sent message. I think we can use a different background color like this.

},
code: {
color: theme.text,
backgroundColor: theme.textBackground,
Copy link
Contributor

Choose a reason for hiding this comment

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

We might consider using a different background color for code blocks so that the markdown in composer appears more consistent with the markdown in sent messages.

@tomekzaw
Copy link
Contributor Author

@shubham1206agra Thanks for your input! We can easily change the blockquote text color if needed, we just need to decide on the actual color.

For the reference, here's what it currently looks like:

light dark

@tomekzaw
Copy link
Contributor Author

tomekzaw commented Jan 12, 2024

@c3024 Thanks for your review. I believe the background color is the same in the composer and in the sent message rgb(247,244,240), it just feels different because there is no border around inline code/codeblock in the composer yet. Adding the border (especially with border radius) is not that easy so we skipped it for now.

Another inconsistency is the background under codeblocks. In a sent message, it appears as a single box with its width equal to the maximum width among all lines of text. Currently, both on Android and iOS, the background color appears only under the actual characters of the inline code/codeblock. This is also something that we need to change.

Finally, there is one more inconsistency on iOS related to font family – the text should be in monospace font but it is not. This might be related to the fact that ExpensifyMono is a different font family than ExpensifyNeue. Fortunately, on Android, it works correctly:

@thienlnam Do you think these inconsistencies (missing border, partial background and incorrect font on iOS) are blocking for us? Should we focus on them right now or can we solve them iteratively?

Also, I have one question regarding codeblocks. Currently, ExpensiMark allows to write code directly after opening ```. This is not consistent with this design which seems to exclude the characters directly after opening ``` from the bordered block with background. How should we approach this?

Screenshot 2024-01-12 at 10 53 53

@thienlnam
Copy link
Contributor

@thienlnam Do you think these inconsistencies (missing border, partial background and incorrect font on iOS) are blocking for us? Should we focus on them right now or can we solve them iteratively?

Most of these are not blockers and we can keep working on iteratively, but the incorrect font on iOS would say is probably the closest to a blocker

As for the partial background - it is kind of obvious at the moment. I don't think it's a huge deal, but in the meantime until we get the border added could we set the background to be transparent for code blocks so it just doesn't show? (It would just show the enclosing quotes in the different font color similar to how block quotes look right now)

Also, I have one question regarding codeblocks. Currently, ExpensiMark allows to write code directly after opening . This is not consistent with this design which seems to exclude the characters directly after opening from the bordered block with background. How should we approach this?

I haven't been able to take this for a test run yet - but are you saying currently in this build if you type out triple backticks it will automatically start formatting the enclosed text even before the user has added the ending triple backticks? If so, I think having this just for the codeblocks is fine. This is how slack also does it so it will be familiar

@tomekzaw
Copy link
Contributor Author

Most of these are not blockers and we can keep working on iteratively, but the incorrect font on iOS would say is probably the closest to a blocker

Thanks for the response. Okay, let's treat missing monospace font on iOS as a blocker (meaning we need to fix it before this PR gets merged).

As for the partial background - it is kind of obvious at the moment. I don't think it's a huge deal, but in the meantime until we get the border added could we set the background to be transparent for code blocks so it just doesn't show? (It would just show the enclosing quotes in the different font color similar to how block quotes look right now)

Sure, we can set background color to transparent for now until we come up with a proper implementation of background with border.

are you saying currently in this build if you type out triple backticks it will automatically start formatting the enclosed text even before the user has added the ending triple backticks?

No, currently the text following the opening triple backticks is not formatted until you close the triple backticks. However, this idea sounds like a reasonable thing to implement, i.e. the closing backticks for the last blockquote in the message are optional. This way, if the user enters triple backticks, the following text will be formatted with monospace font and we avoid a content "jump" when the last closing backtick is added. I think this would be beneficial for user experience. Let us know what you think, we could implement it in ExpensiMark. cc @robertKozik

What I meant to ask in the original question was where exactly should we place the rectangle with border and background for the following input:

Screenshot 2024-01-12 at 14 23 24

As you can see, aaa is placed in the same line as opening triple backticks, so we cannot start the background in the next line (bbb) because aaa would be outside of it. Similarly, ddd is placed in the same line as closing triple backticks, so we also need to include it in the rectangle.

I think the best approach here would be to disallow any characters after opening triple backticks. Effectively, this would mean that the user needs to add a newline directly after triple backticks in order for the text to be formatted. Similarly, we would need to disallow any characters in the same line before closing triple backticks.

Alternatively, we can place the triple backticks inside the rectangle with background and border (either always or only if there are any characters directly after opening triple brackets).

@robertKozik
Copy link
Contributor

Formatting the non-enclosed code block is feasible. However, currently, the user's intent can be ambiguous. For instance, typing ``` followed by any string with Markdown tags might lead to a situation where inside the Markdown input, it is formatted as a code block (with other tags inside not being parsed). Yet, after sending, it will appear as just triple backticks followed by a formatted string.

@shubham1206agra
Copy link
Contributor

I think the best approach here would be to disallow any characters after opening triple backticks. Effectively, this would mean that the user needs to add a newline directly after triple backticks in order for the text to be formatted. Similarly, we would need to disallow any characters in the same line before closing triple backticks.

In my opinion, this should be preferred given every platform markdown works like this.

@thienlnam
Copy link
Contributor

Thanks, for this PR then let's aim to

  • fix missing monospace font on iOS
  • set background color to transparent for codeblocks
  • Resolve any more major bugs that we find from QA / testing

Re the automatic formatting - we've had a previous discussion in the pre-design regarding this and decided not to automatically format any of the text until the ending text for the initial version (discussion here. Something I think we can revisit once we've had some time using this

I think the best approach here would be to disallow any characters after opening triple backticks. Effectively, this would mean that the user needs to add a newline directly after triple backticks in order for the text to be formatted. Similarly, we would need to disallow any characters in the same line before closing triple backticks.

Agreed, I think we can go with this

@tomekzaw
Copy link
Contributor Author

I've pushed fixes for these two issues:

  • fix missing monospace font on iOS
  • set background color to transparent for codeblocks

iOS (dark theme):
ios_dark

iOS (light theme):
ios_light

Android (dark theme):
android_dark

Android (light theme):
android_light

@tomekzaw
Copy link
Contributor Author

I've pushed a commit that updates the dependency. Can we please run an adhoc build and test the feature? cc @thienlnam

@shubham1206agra
Copy link
Contributor

@thienlnam @tomekzaw I am unable to access the live markdown repo now. Can you give us access?

Copy link
Contributor

🧪🧪 Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing! 🧪🧪

Android 🤖 iOS 🍎
❌ FAILED ❌ ❌ FAILED ❌
The QR code can't be generated, because the android build failed The QR code can't be generated, because the iOS build failed
Desktop 💻 Web 🕸️
❌ FAILED ❌ ❌ FAILED ❌
The QR code can't be generated, because the Desktop build failed The QR code can't be generated, because the web build failed

👀 View the workflow run that generated this build 👀

@shubham1206agra
Copy link
Contributor

@tomekzaw Can you merge main?

@tomekzaw
Copy link
Contributor Author

@shubham1206agra Done

@shubham1206agra
Copy link
Contributor

shubham1206agra commented Jan 23, 2024

Screenshot 2024-01-23 at 3 19 39 PM

Underline seems to be on wrong place on using []() syntax for link. Should be discussed as slack has the original one.

@shubham1206agra
Copy link
Contributor

shubham1206agra commented Jan 23, 2024

Screen.Recording.2024-01-23.at.3.28.08.PM.mov

@tomekzaw Typing mention tries to open mention dialog again and again. It has a weird stuttering too when I tried to clear input using Backspace

@shubham1206agra
Copy link
Contributor

Screen.Recording.2024-01-23.at.3.33.22.PM.mov

@shubham1206agra
Copy link
Contributor

Screenshot_2024-01-31-08-33-50-001_com expensify chat adhoc
This weird thing happening with display name when I send this particular message

This is still not fixed

@tomekzaw I am able to repro this on desktop main. You can skip this for now.

@shubham1206agra
Copy link
Contributor

Screenshot 2024-01-23 at 4 16 51 PM We have difference in output and preview for this. May need to decide which is correct. Strike and italics have same as preview.

This is also not fixed

I believe this is a problem with ExpensiMark instead of preview. But we need to fix this to make it consistent across.

@tomekzaw
Copy link
Contributor Author

tomekzaw commented Feb 1, 2024

Thanks @shubham1206agra for pointing out these bugs, I must have overlooked them!

  1. Invalid layout of nested blockquotes on Android Live Markdown Preview #34292 (comment) – this is indeed a bug but also an edge-case so let's treat is as non-blocking and fix in a follow-up PR
  2. Inconsistency of formatting between composer and history – this is because Live Markdown uses a different (newer) version of ExpensiMark than App; there's already a PR that bumps ExpensiMark in the app and we want to avoid git conflicts; we will align the versions in a follow-up PR
  3. Missing display name when sending particular message Live Markdown Preview #34292 (comment) – we were also not able to reproduce; skipping this as you suggested

@tomekzaw
Copy link
Contributor Author

tomekzaw commented Feb 1, 2024

Merged main. FYI the tests are failing because of this error:

npm WARN tarball tarball data for react-native-flipper@https://gitpkg.now.sh/facebook/flipper/react-native/react-native-flipper?9cacc9b59402550eae866e0e81e5f0c2f8203e6b
(sha512-M784S/qPuN/HqjdvXg98HIDmfm0sF8mACc56YNg87nzEF90zKSKp0XyOE83SEW+UJX2Gq/rf9BvM2GZeXlrhnQ==)
seems to be corrupted. Trying again.

@robertKozik
Copy link
Contributor

Screenshot 2024-01-23 at 4 16 51 PM We have difference in output and preview for this. May need to decide which is correct. Strike and italics have same as preview.

This is also not fixed

I believe this is a problem with ExpensiMark instead of preview. But we need to fix this to make it consistent across.

@shubham1206agra Can you check one more time? I've build the latest version of this branch and now output and preview is consistent

image

@shubham1206agra
Copy link
Contributor

@robertKozik This is fixed now.

@c3024
Copy link
Contributor

c3024 commented Feb 1, 2024

I tried all common patterns and whatever combinations I could think of

livemarkdownChrome.mp4
Screenshot 2024-02-01 at 10 50 56 PM

LGTM

@thienlnam
Copy link
Contributor

We're close to merging - checks are failing for all PRs here https://expensify.slack.com/archives/C01GTK53T8Q/p1706808000490579 but once that is resolved we should be good

@c3024
Copy link
Contributor

c3024 commented Feb 1, 2024

Sorry, I just found this issue.

Screen.Recording.2024-02-01.at.11.28.52.PM.mov

If the last line happens to be with triple back ticks previous lines' formatting is lost. In this video the website link's formatting is lost.

Please check.

@tomekzaw @robertKozik

@tomekzaw
Copy link
Contributor Author

tomekzaw commented Feb 1, 2024

@c3024 Thanks for finding and reporting this issue. There is one case when we deliberately skip formatting: when we are unable to restore the original Markdown string from HTML returned by ExpensiMark. It looks like you have found a Markdown message that, once converted into HTML and back to Markdown, is different than the original input. This is not an issue with MarkdownTextInput component itself; it's an issue with our ExpensiMark->JS parser pipeline. This is something that we can fix after merging or even skip fixing this if we want to use a different Markdown parser in near future.

cc @thienlnam

@thienlnam thienlnam merged commit 63ba91f into Expensify:main Feb 1, 2024
16 checks passed
@OSBotify
Copy link
Contributor

OSBotify commented Feb 1, 2024

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@tomekzaw tomekzaw deleted the @tomekzaw/live-markdown branch February 2, 2024 10:51
@Skalakid Skalakid mentioned this pull request Feb 5, 2024
50 tasks
@OSBotify
Copy link
Contributor

OSBotify commented Feb 5, 2024

🚀 Deployed to production by https://github.com/marcaaron in version: 1.4.36-5 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

borderColor: theme.border,
borderWidth: 4,
marginLeft: 0,
paddingLeft: 6,
Copy link
Contributor

Choose a reason for hiding this comment

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

Blockquote element has style of inline-block which is forcing cursor to be inside of this block and overlap with characters. We solved this by adding padding-right so that cursor has some space for itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI paddingRight is a no-op on mobile (Android & iOS), it works only on web.

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

Successfully merging this pull request may close these issues.

8 participants