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

Implement Block quote HTML to markdown conversion #4188

Closed
3 tasks
Jag96 opened this issue Jul 23, 2021 · 17 comments
Closed
3 tasks

Implement Block quote HTML to markdown conversion #4188

Jag96 opened this issue Jul 23, 2021 · 17 comments
Assignees
Labels
Engineering External Added to denote the issue can be worked on by a contributor Improvement Item broken or needs improvement. Weekly KSv2

Comments

@Jag96
Copy link
Contributor

Jag96 commented Jul 23, 2021

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


Related to #3047, similar to Expensify/expensify-common#392. Blockquote MD->HTML version can be found here

Action Performed:

Copied a blockquote message from slack to E.cash
image
image

Expected Result:

The message should contain markdown to create a blockquote in E.cash
image

Actual Result:

Message just pasted text

Platform:

Where is this issue occurring?

  • Web
  • Desktop App
  • Mobile Web

View all open jobs on Upwork

view this job on Upwork

@Jag96 Jag96 added the AutoAssignerTriage Auto assign issues for triage to an available triage team member label Jul 23, 2021
@MelvinBot
Copy link

Triggered auto assignment to @zanyrenney (AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.

@MelvinBot MelvinBot removed the AutoAssignerTriage Auto assign issues for triage to an available triage team member label Jul 23, 2021
@zanyrenney zanyrenney removed their assignment Jul 23, 2021
@MelvinBot
Copy link

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

@pecanoro pecanoro added Weekly KSv2 Improvement Item broken or needs improvement. External Added to denote the issue can be worked on by a contributor labels Jul 23, 2021
@MelvinBot
Copy link

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

@MelvinBot MelvinBot added Daily KSv2 and removed Weekly KSv2 labels Jul 23, 2021
@pecanoro pecanoro removed their assignment Jul 23, 2021
@tugbadogan
Copy link
Contributor

Hi,

I would like to work on this issue. Here is my proposal:

  • I will add following regex rule for blockquote HTML to markdown conversion to htmlToMarkdownRules array in ExpensiMark library.
{
    name: 'quote',
    regex: /<(blockquote|q)(?:"[^"]*"|'[^']*'|[^'">])*>(.*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))/gi,
    replacement: '> $2'
},

https://github.com/Expensify/expensify-common/blob/7d8408c5c78792394eee8e079f115b1380221a23/lib/ExpensiMark.js#L167-L174

  • Also I will add unit test for this conversion to ExpensiMark-Markdown-test.

https://github.com/Expensify/expensify-common/blob/cf78cdc764ac17fb2aaa8b73626cca64c3aa565f/__tests__/ExpensiMark-Markdown-test.js

I have a question. I'm assuming that we're already calling HTML to markdown conversion function when a rich text is pasted from Slack. Is that right?

@SofiedeVreese
Copy link
Contributor

I'm out of office- readding External label to reassign.

@MelvinBot MelvinBot removed the Overdue label Jul 26, 2021
@SofiedeVreese SofiedeVreese removed their assignment Jul 26, 2021
@SofiedeVreese SofiedeVreese added External Added to denote the issue can be worked on by a contributor and removed External Added to denote the issue can be worked on by a contributor labels Jul 26, 2021
@MelvinBot
Copy link

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

@jboniface jboniface added Exported Weekly KSv2 and removed Daily KSv2 labels Jul 26, 2021
@MelvinBot MelvinBot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jul 26, 2021
@MelvinBot
Copy link

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

@jboniface
Copy link

@deetergp this has a pending proposal here, please review

@parasharrajat
Copy link
Member

parasharrajat commented Jul 26, 2021

Proposal

  1. we can follow the existing pattern of finding the tags by similar regex which I added for ~,*,_ parsing with one exception that we have to break the newlines into multiple quotes. We also optionally include the preceding newline. So that we don't insert two newlines after replacement.

  2. It will require creating a new rule in the htmlToMarkdownRules in ExpensiMark.
    as follows

{
                name: 'quote',
                regex: /\n?<(blockquote|q)(?:"[^"]*"|'[^']*'|[^'">])*>((?:.|\n)*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))/gi,
                replacement: (match, g1, g2) => {
                   const resultString = g2.trim().split('\n').map(m => `> ${m}`).join('\n')
                    return `\n${resultString}\n`;
                }
            },

@deetergp
Copy link
Contributor

This GH seems to assume that there will be something in the paste buffer when you copy block-quoted text out of slack. But when I dump some lorem ipsum into a blockquote in Slack, copy it to the buffer, then dump it into terminal, there's nothing. And if I dump it into Google Docs, it retains a bit of the background color from Slack, but nothing else that would indicate a blockquote. Am I missing something here?

Screen Shot 2021-07-28 at 9 52 46 AM

Screen Shot 2021-07-28 at 9 53 06 AM

Screen Shot 2021-07-28 at 9 53 23 AM

@parasharrajat
Copy link
Member

terminal only supports plain text. HTML formatting it lost while pasting. Github| Slack accepts HTML formatting thus they remain quoted

@deetergp
Copy link
Contributor

Ah, I see. The problem was with how much I was selecting to copy from Slack. If I include the timestamp, then pasting it back into Slack includes the block-quoting. @parasharrajat Can you show me an example of what your solution does that @tugbadogan's does not?

@parasharrajat
Copy link
Member

Yeah, @deetergp.

Take this as example

<blockquote>RegExr was created by gskinner.com, and is proudly hosted by Media Temple

  Edit the Expression & Text to see matches. Roll over matches or the expression for details. PCRE & JavaScript 
</blockquote>

Blockquote can contain newlines between text.

you paste a quote with newlines in expensify as

> a quote
> multi
> 
> can have a empty line as well.

My regex will handle multi-lines as well. Now there could be an existing line break before the Quote while pasting. We always surround the quote with new lines. and if there was an existing newline before the quote while pasting then we should not add another newline before the quote. My solution handles that as well. She just missed this part.

@deetergp
Copy link
Contributor

That does seem rather important @parasharrajat, let's go with your solution.

@MelvinBot
Copy link

@deetergp, @jboniface it looks like no one is assigned to work on this job.
Please double the price or add a comment stating why the job isn't being doubled.

@jboniface jboniface removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 3, 2021
@jboniface
Copy link

I don't know why melvin is spamming that message when this is already hired out 🤔

@parasharrajat
Copy link
Member

This is paid and can be closed.

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 Improvement Item broken or needs improvement. Weekly KSv2
Projects
None yet
Development

No branches or pull requests

9 participants