Strikethrough text is not working as expected if there's a space before the ~
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:
- Navigate to a conversation
- 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

Expensify/Expensify Issue URL:
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
Triggered auto assignment to @sophiepintoraetz (AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.
Copied the text and performed Step 2 in the web version and was able to reproduce:

Triggered auto assignment to @nickmurray47 (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
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.
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>))
@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?
Yes, it can be. Adding the label.
Triggered auto assignment to @puneetlath (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
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.

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* itemThe 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
Upwork job post added: https://www.upwork.com/jobs/~0185450afd7993674c
@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>))
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?
which tag specifically? bold. Markdown means everything.
@isagoico would you mind giving a list of each individual markdown that is affected by this issue?
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:

Just a question @puneetlath:
do we want ~ string~ to return unformatted too? or only ~string~
Seems like markdowns for:
- Bold
- Strikethrough
- Italic
- Code
Are affected by this.
@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|_)`(.*?[^\s])`(\B|_)(?![^<]*<\/pre>)/g
@puneetlath bumped back to daily, can you review the above proposals? Thx
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 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.