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

[$1000] Copying code blocks from chat is broken #7644

Closed
mvtglobally opened this issue Feb 9, 2022 · 64 comments
Closed

[$1000] Copying code blocks from chat is broken #7644

mvtglobally opened this issue Feb 9, 2022 · 64 comments
Assignees
Labels
Engineering External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors Reviewing Has a PR in review Weekly KSv2

Comments

@mvtglobally
Copy link

mvtglobally commented Feb 9, 2022

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Action Performed:

  1. Navigate to any chat
  2. Copy any code block
  3. paste in chat

Expected Result:

User should be able to copy and paste code blocks

Actual Result:

What ends up being copied to your clipboard is not the content that is highlighted

Workaround:

unknown

Platform:

Where is this issue occurring?

  • Web
  • iOS
  • Android
  • Desktop App
  • Mobile Web

Version Number: 1.1.37-0
Reproducible in staging?: Y
Reproducible in production?: Y
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation

Recording.391.mp4

Expensify/Expensify Issue URL:
Issue reported by: @puneetlath
Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1643914668204029

Job Post https://www.upwork.com/jobs/~0103d56637d4154cbd

View all open jobs on GitHub

@MelvinBot
Copy link

Triggered auto assignment to @aldo-expensify (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

@aldo-expensify aldo-expensify added the External Added to denote the issue can be worked on by a contributor label Feb 9, 2022
@MelvinBot
Copy link

Triggered auto assignment to @kevinksullivan (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

@MelvinBot
Copy link

Triggered auto assignment to Contributor-plus team member for initial proposal review - @rushatgabhane (Exported)

@MelvinBot MelvinBot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Feb 10, 2022
@MelvinBot
Copy link

Triggered auto assignment to @iwiznia (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@ihamzanizami
Copy link

Hey,
I saw your job posting and I understand that you are looking for a react native developer to solve an existing issue in your code that is related to copying code blocks.
I have been working on React Native for over 5 years now and I have used the clipboard feature of react-native in a number of projects.
I will be using the clipboard feature provided by React native which will get a string and that string will be set to a data value and the user will be able to paste that data anywhere he wants.
I am willing to start right away and can provide you with a solution in less than 36 hours.
I would like to discuss further details with you before proceeding, I would suggest that we hop onto a call right away!
Looking forward to your response,
Kind regards,
Hamza Nizami

@aldo-expensify
Copy link
Contributor

👋 @ihamzanizami , I suggest you read https://github.com/Expensify/App/blob/main/CONTRIBUTING.md to learn how contributors can participate and propose solutions.

@iwiznia
Copy link
Contributor

iwiznia commented Feb 10, 2022

I don't understand this issue. I see that the code is pasted correctly in that video. Can someone explain the problem in more detail please?

@aldo-expensify
Copy link
Contributor

I understand that the problem are the line breaks. When I copy code blocks, I always have to fix line breaks manually.

@iwiznia
Copy link
Contributor

iwiznia commented Feb 10, 2022

Oh, I see. FWIW it works properly if you CMD+SHIFT+V (paste without format)

@ahmdshrif
Copy link
Contributor

ahmdshrif commented Feb 10, 2022

Proposal

issue happend on htmlconverter . since the code block is formated with html .
code formate use <div> as a new line and we net parse this on library.

we can fix this by just parsing the div as new line /n or <br/> and html converter will count it as a new line.

in

const markdownText = parser.htmlToMarkdown(html);

+ const fixHtml = html.replaceAll('<div>', '').replaceAll('</div>', '<br/>');
- const markdownText = parser.htmlToMarkdown(html); 
+ const markdownText = parser.htmlToMarkdown(fixHtml); 

we can fix this from the library also by edit this.

            {
                name: 'newline',

                // Replaces open and closing <br><br/> tags with a single <br/>
                // Slack uses special <span> tag for empty lines instead of <br> tag
                pre: inputString => inputString.replace('<br></br>', '<br/>').replace('<br><br/>', '<br/>')
                    .replace(SLACK_SPAN_NEW_LINE_TAG + SLACK_SPAN_NEW_LINE_TAG, '<br/><br/><br/>').replace(SLACK_SPAN_NEW_LINE_TAG, '<br/><br/>'),

                // Include the immediately followed newline as `<br>\n` should be equal to one \n.
                regex: /<br(?:"[^"]*"|'[^']*'|[^'"><])*>\n?/gi,
                replacement: '\n'
            },

to

                pre: inputString => inputString .replaceAll('<div>', '').replaceAll('</div>', '<br/>')replace('<br></br>', '<br/>').replace('<br><br/>', '<br/>')
                    .replace(SLACK_SPAN_NEW_LINE_TAG + SLACK_SPAN_NEW_LINE_TAG, '<br/><br/><br/>').replace(SLACK_SPAN_NEW_LINE_TAG, '<br/><br/>'),

Screen Shot 2022-02-11 at 12 39 47 AM

@rushatgabhane
Copy link
Member

            pre: inputString => inputString .replaceAll('<div>', '').replaceAll('</div>', '<br/>')replace('<br></br>', '<br/>').replace('<br><br/>', '<br/>')
                .replace(SLACK_SPAN_NEW_LINE_TAG + SLACK_SPAN_NEW_LINE_TAG, '<br/><br/><br/>').replace(SLACK_SPAN_NEW_LINE_TAG, '<br/><br/>'),

@ahmdshrif that didn't work for me.
I modified the new line rule of htmlToMarkdownRules

@ahmdshrif
Copy link
Contributor

We just modified the pre with this not all object

@ahmdshrif
Copy link
Contributor

ahmdshrif commented Feb 14, 2022

you can apply the changes on
/node_modules/expensify-common/lib/ExpensiMark.js
line 197

https://github.com/Expensify/expensify-common/blob/main/lib/ExpensiMark.js#L197

 {
                name: 'newline',

                // Replaces open and closing <br><br/> tags with a single <br/>
                // Slack uses special <span> tag for empty lines instead of <br> tag
-                pre: inputString => inputString.replace('<br></br>', '<br/>').replace('<br><br/>', '<br/>')
+                pre: inputString => inputString .replaceAll('<div>', '').replaceAll('</div>', '<br/>').replace('<br></br>', '<br/>').replace('<br><br/>', '<br/>')
                .replace(SLACK_SPAN_NEW_LINE_TAG + SLACK_SPAN_NEW_LINE_TAG, '<br/><br/><br/>').replace(SLACK_SPAN_NEW_LINE_TAG, '<br/><br/>'),
                

                // Include the immediately followed newline as `<br>\n` should be equal to one \n.
                regex: /<br(?:"[^"]*"|'[^']*'|[^'"><])*>\n?/gi,
                replacement: '\n'
            },

sure we will not edit on node module but we will add the changes on expensify-common library repo but you can test on by change on node module

@rushatgabhane
Copy link
Member

rushatgabhane commented Feb 14, 2022

@ahmdshrif yep, that's exactly what I tried. It didn't work.

Btw, I'm testing by pasting this text -

if (files.length > 0) {
// Prevent the default so we do not post the file name into the text box
event.preventDefault();
this.props.onPasteFile(event.clipboardData.files[0]);
return;

@ahmdshrif
Copy link
Contributor

ahmdshrif commented Feb 14, 2022

@rushatgabhane ok, GitHub uses td and tr Tags for new line, not div as VScode.
so just add them. like this will work on both.

pre: inputString => inputString.replaceAll('<div>', '').replaceAll('</div>', '<br/>').replaceAll('</td></tr>', '<br/>').replace('<br></br>', '<br/>').replace('<br><br/>', '<br/>')
.replace(SLACK_SPAN_NEW_LINE_TAG + SLACK_SPAN_NEW_LINE_TAG, '<br/><br/><br/>').replace(SLACK_SPAN_NEW_LINE_TAG, '<br/><br/>'),

@rushatgabhane
Copy link
Member

@ahmdshrif thanks, that fixed it for copying form github.

Copying 1 line from vscode pastes 2 extra lines.
image

@rushatgabhane
Copy link
Member

rushatgabhane commented Mar 21, 2022

@ahmdshrif could you please repost your proposal here? And slightly customize it for this issue.
It'll make it easier for @ iwiznia to review it. Thanks a lot! 🙇‍♂️

@ahmdshrif
Copy link
Contributor

ahmdshrif commented Mar 22, 2022

sure @rushatgabhane
@iwiznia we have an issue here when copying text from the text editor because it uses div to make a new line
and that is what we try to fix on both issues.

so I add the regex before here and it work fine but did not work on the second issue so I replace it with some logic explained here #7352 (comment) to work with both.

but we still have here another issue here when copy code form github . github use <td> and <tr> (tables) to map new lines and to fix that i add this regex .replaceAll(/(<tr.*?<\/tr>)/g,"$1<br/>")

I also explain this regex and the first regex (we replace it ) on this comment #7644 (comment)

as summary we will fix mapping dev on the second issue but we still need to fix copy form github buy use this regex
.replaceAll(/(<tr.*?<\/tr>)/g,"$1<br/>")

thanks .

@rushatgabhane
Copy link
Member

🎀 👀 🎀 C+ reviewed

@iwiznia I know this isn't very pretty, but the only other alternative is to use a third party markdown-html parser. But as Rory and I discussed, it's a very long term project that may or may not come into fruition.

I recommend @ahmdshrif's proposal.

@iwiznia
Copy link
Contributor

iwiznia commented Mar 24, 2022

Where exactly will that code go? (sorry if it is linked somewhere, but could not find it following the linked comments)

Wouldn't those regexes also match other things? Like what if I am pasting an HTML string? Ie: what if what I am pasting is <tr><td>Hello!</td></tr>, would that get replaced or is the escaping of html characters happening before and thus would work?

@rushatgabhane
Copy link
Member

#7644 (comment)

@ahmdshrif ^^

@ahmdshrif
Copy link
Contributor

sorry @iwiznia for making it confusing
I mention it early here #7644 (comment) and forget to add it to the final proposal

when past text we check if it contains HTML format and if yes we pare it with htmlToMarkdown

const markdownText = parser.htmlToMarkdown(html);

so the library has its own mechanism to just pares the HTML style tags.

but the issue in the library is it only maps br tag to newline and not handle the table case
so we only will add this line to the HTML parser role
https://github.com/Expensify/expensify-common/blob/main/lib/ExpensiMark.js#L197

 {
                name: 'newline',

                // Replaces open and closing <br><br/> tags with a single <br/>
                // Slack uses special <span> tag for empty lines instead of <br> tag
              pre: inputString => inputString.replace('<br></br>', '<br/>').replace('<br><br/>', '<br/>')
+               .replaceAll(/(<tr.*?<\/tr>)/g,"$1<br/>")
                .replace(SLACK_SPAN_NEW_LINE_TAG + SLACK_SPAN_NEW_LINE_TAG, '<br/><br/><br/>').replace(SLACK_SPAN_NEW_LINE_TAG, '<br/><br/>'),
                

                // Include the immediately followed newline as `<br>\n` should be equal to one \n.
                regex: /<br(?:"[^"]*"|'[^']*'|[^'"><])*>\n?/gi,
                replacement: '\n'
            },

for div handling l already implement it on this PR https://github.com/Expensify/expensify-common/pull/436/files

copy you example : -
Screen Shot 2022-03-25 at 1 52 39 PM

copy form github

Screen Shot 2022-03-25 at 1 53 34 PM

@iwiznia
Copy link
Contributor

iwiznia commented Mar 25, 2022

Got it, thanks for clarifying! The proposal makes sense @jboniface please hire @ahmdshrif

@jboniface
Copy link

jboniface commented Mar 25, 2022

@ahmdshrif
Copy link
Contributor

ahmdshrif commented Mar 25, 2022

@jboniface the link does not work
Screen Shot 2022-03-25 at 8 28 16 PM

@jboniface
Copy link

@ahmdshrif oops, i sent you the link for the proposal reviews 😵‍💫
it's this: https://www.upwork.com/jobs/~0103d56637d4154cbd

@ahmdshrif
Copy link
Contributor

ahmdshrif commented Mar 25, 2022

no problem @jboniface 😄
applied.

@ahmdshrif
Copy link
Contributor

pr ready here Expensify/expensify-common#436

@jboniface jboniface added the Reviewing Has a PR in review label Apr 6, 2022
@melvin-bot melvin-bot bot removed the Overdue label Apr 6, 2022
@rushatgabhane
Copy link
Member

Review almost done

@ahmdshrif ahmdshrif mentioned this issue Apr 21, 2022
90 tasks
@rushatgabhane
Copy link
Member

All set here, PR merged

@rushatgabhane
Copy link
Member

PR #8743 hit production 2 days ago.

@ahmdshrif
Copy link
Contributor

Bump @jboniface

@jboniface
Copy link

@rushatgabhane please apply for the C+ payment https://www.upwork.com/jobs/~0103d56637d4154cbd

@rushatgabhane
Copy link
Member

@jboniface unfortunately, that job is no longer available.

@jboniface
Copy link

@rushatgabhane ok, let's use this one https://www.upwork.com/jobs/~01b9b2c4c22ea68332

@rushatgabhane
Copy link
Member

Thanks!

@mallenexpensify
Copy link
Contributor

@ahmdshrif has been paid (by Jeremy), is there a reason he wasn't assigned to this issue?
@rushatgabhane I hired you, let me know when you've accepted and we'll pay.
https://www.upwork.com/jobs/~01b9b2c4c22ea68332

@rushatgabhane
Copy link
Member

rushatgabhane commented Jun 1, 2022

is there a reason he wasn't assigned to this issue

@ahmdshrif was given the approval, so it's proly a small boo boo

@mallenexpensify accepted, thank you!

@mallenexpensify
Copy link
Contributor

Paid @rushatgabhane $1k for C+

Thanks for the help y'all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Engineering External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors Reviewing Has a PR in review Weekly KSv2
Projects
None yet
Development

No branches or pull requests