App icon indicating copy to clipboard operation
App copied to clipboard

Strikethrough text is not working as expected if there's a space before the ~

Open isagoico opened this issue 5 years ago • 39 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Expected Result:

Text shouldn't be strikethrough

Actual Result:

Text is strikethrough

Action Performed:

  1. Navigate to a conversation
  2. Send this text ~this text shouldn't be crossed if there's a space behind ~ test

Workaround:

No need, visual issue.

Platform:

Where is this issue occurring?

Web ✔️ iOS Android Desktop App Mobile Web

Version Number: 1.0.43-0

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos: Any additional supporting documentation

image

Expensify/Expensify Issue URL:

View all open jobs on Upwork


From @mallenexpensify https://expensify.slack.com/archives/C01GTK53T8Q/p1620845857125700

When using multiple ~ in chat, markdown treats them as strikethrough. When there is a space before the second ~ we shouldn't use that to denote the markdown.

Upwork job post: https://www.upwork.com/jobs/~0185450afd7993674c

isagoico avatar May 13 '21 01:05 isagoico

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

MelvinBot avatar May 13 '21 01:05 MelvinBot

Copied the text and performed Step 2 in the web version and was able to reproduce: image

sophiepintoraetz avatar May 13 '21 03:05 sophiepintoraetz

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

MelvinBot avatar May 13 '21 03:05 MelvinBot

Info looks all there and looks like we will need to make adjustments in expensify-common's markdown rules. Have a lot on my plate atm so unassigning for now.

nickmurray47 avatar May 18 '21 17:05 nickmurray47

This requires just a drop in adjustment to the strikethrough's Regex on ExpensiMark.

/\B~(.*?)~\B(?![^<]*(<\/pre>|<\/code>|<\/a>))/g,

TO ↓

          
\B~(.*?)[^\s]~\B(?![^<]*(<\/pre>|<\/code>|<\/a>))

parasharrajat avatar May 18 '21 18:05 parasharrajat

@nickmurray47 Do you think this can be worked on by a contributor? If so, can you add the External label so it'll be assigned to a contributor manager?

mallenexpensify avatar May 20 '21 23:05 mallenexpensify

Yes, it can be. Adding the label.

nickmurray47 avatar May 20 '21 23:05 nickmurray47

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

MelvinBot avatar May 20 '21 23:05 MelvinBot

All markdowns are affected by this. This is another example of how the markdown is being considered for a text even if there is a space in front of it.

image image


From @rafecolton https://expensify.slack.com/archives/C01GTK53T8Q/p1622166086353200

Markdown is not formatted correctly for bolded item appearing inside a bulleted list:

* This is a bulleted list containing a *bold* item The above appears like this (rendered with an extra space in front that Slack deletes): This is a bulleted list containing a bold* item And it should appear like this (but with an * instead of a • since we are not doing bullets now afaik): This is a bulleted list containing a bold item

isagoico avatar May 28 '21 20:05 isagoico

Upwork job post added: https://www.upwork.com/jobs/~0185450afd7993674c

puneetlath avatar Jun 08 '21 20:06 puneetlath

@puneetlath I would like to work on this.

Proposal

This requires just a drop in adjustment to the strikethrough's Regex on ExpensiMark in e-common repo.

/\B~(.*?)~\B(?![^<]*(<\/pre>|<\/code>|<\/a>))/g,

TO ↓

\B~(.*?[^\s])~\B(?![^<]*(<\/pre>|<\/code>|<\/a>))

parasharrajat avatar Jun 08 '21 20:06 parasharrajat

Thanks @parasharrajat. It looks like according to @isagoico this is happening for other markdown as well, not just strikethrough. Would the solution for others be similar?

puneetlath avatar Jun 08 '21 20:06 puneetlath

which tag specifically? bold. Markdown means everything.

parasharrajat avatar Jun 08 '21 20:06 parasharrajat

@isagoico would you mind giving a list of each individual markdown that is affected by this issue?

puneetlath avatar Jun 08 '21 20:06 puneetlath

Proposal

We have the following markdown styles in our expensify-common/ExpensiMark: bold, italic, strikethrough, quote and inlineCodeBlock. Only quote doesn't need fixing since it uses a single char (>) to format and whitespaces are dealt with correctly.

We can fix this by excluding from our regex parser matches where the second formatter (~, *, `, etc..) is preceded by a whitespace. This can be done by using a negative lookbehind or adding a negated set.

Working example: Screen Shot 2021-06-18 at 12 16 04 AM

Just a question @puneetlath: do we want ~ string~ to return unformatted too? or only ~string~

rdjuric avatar Jun 18 '21 03:06 rdjuric

Seems like markdowns for:

  • Bold
  • Strikethrough
  • Italic
  • Code

Are affected by this.

isagoico avatar Jun 19 '21 10:06 isagoico

@puneetlath Based on the input of isagoico. I confirm that the same solution (previously posted https://github.com/Expensify/Expensify.cash/issues/2846#issuecomment-857091830) will work for all types of markdown rules. We just need to negate the space before the main symbol. So here are the changes.

Bold

/\B\*(.*?[^\s])\*\B(?![^<]*(<\/pre>|<\/code>|<\/a>))/g

Italic

/(?!_blank">)\b_(.*?[^\s])_\b(?![^<]*(<\/pre>|<\/code>|<\/a>))/g

Strikethrough

/\B~(.*?[^\s])~\B(?![^<]*(<\/pre>|<\/code>|<\/a>))/g

Inline Code block

I don't think we should do that as GitHub doesn't do that either. But here it is, in case we want to do it. /(\B|_)&#x60;(.*?[^\s])&#x60;(\B|_)(?![^<]*<\/pre>)/g

parasharrajat avatar Jun 20 '21 16:06 parasharrajat

@puneetlath bumped back to daily, can you review the above proposals? Thx

mallenexpensify avatar Jun 21 '21 18:06 mallenexpensify

Ok so just so we're on the same page. Is this right?

We do want the markdown to apply when there is a space after:

  • inline code block
  • code fence
  • quote

We don't want markdown to apply when there is a space after:

  • italic
  • bold
  • strikethrough

puneetlath avatar Jun 22 '21 23:06 puneetlath

@puneetlath Just to sure. Are you talking about the space after the starting symbol? for eg:

V
~ I am ~

Or space before ending symbol (original issue). Also, I think we can move forward to quickly wrap up this on.

parasharrajat avatar Jun 24 '21 12:06 parasharrajat