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

Add Messaging Markdown (light) Support #552

Merged
merged 1 commit into from May 2, 2024
Merged

Conversation

sternetj
Copy link
Contributor

@sternetj sternetj commented May 1, 2024

Changes

  • Adds some basic markdown support to the DirectMessageScreen and the MessageScreen (list of messages)
  • Adds formatting of email, phone, and urls to the DirectMessageScreen and the MessageScreen (list of messages)

Supported Markdown

  • [text](https://google.com) - renders a link. Example: text
  • ***text*** - renders text as bold and italic. Example: text
  • **text** or __text__ - renders text as bold. Example: text
  • *text* or _text_ - renders text as italic. Example: text
  • ~~text~~ - renders text as strikethrough. Example: text
  • ![image](https://reactnative.dev/img/tiny_logo.png) - renders an image in it's own bubble. Example:
    image

Note: Markdown does not support nested styling. i.e. Markdown like **Bold text with _emphasis_ text** will not italicize the text, it will look like this: Bold text with _emphasis_ text. The desired result can be achieved with the following **Bold text with** ***emphasis*** **text** which looks like this: Bold text with emphasis text

Screenshots

messaging-markdown.mov
RPReplay_Final1714584385.MP4

Copy link

@rob-snyder rob-snyder left a comment

Choose a reason for hiding this comment

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

Seems largely okay given my near non-existent knowledge

Comment on lines +83 to +93
messages.push({
...message,
_id: `${message._id}-${i}`,
text: parts[0].trim(),
});
messages.push({
...message,
_id: `${message._id}-${i}-image`,
text: '',
image: imageUrl,
});

Choose a reason for hiding this comment

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

I'm not familiar with the repo much less this feature, but this seems odd to me. You're adding the message twice and just changing whether it's image or text? Why not just

Suggested change
messages.push({
...message,
_id: `${message._id}-${i}`,
text: parts[0].trim(),
});
messages.push({
...message,
_id: `${message._id}-${i}-image`,
text: '',
image: imageUrl,
});
messages.push({
...message,
_id: `${message._id}-${i}`,
text: parts[0].trim(),
image: imageUrl,
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gifted chat renders the text below the image. For markdown images, we want them to appear in the order they were written so this splits the message up by image occurrences and interleaves them correctly.

Example: For the following markdown

Picture 1
![some-pic](https://some-url.com/1)
Picture 2
![some-pic-2](https://some-url.com/2)
Aren't these cool?

If we put the image on the message, gifted chat would display

<some-pic-1>
Picture 1
<some-pic-2>
Picture 2
Aren't these cool?

With my proposed solution we would see

Picture 1
<some-pic-1>
Picture 2
<some-pic-2>
Aren't these cool?

@sternetj sternetj merged commit 56c9e3b into master May 2, 2024
3 checks passed
@sternetj sternetj deleted the message-markdown-support branch May 2, 2024 20:21
Copy link

github-actions bot commented May 2, 2024

🎉 This PR is included in version 12.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot added the released Has been released to the package repository (NPM, etc) label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Has been released to the package repository (NPM, etc)
Projects
None yet
2 participants