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 an escaper for the "hide link embed" markdown sequence #9852

Open
janparisek opened this issue Sep 26, 2023 · 1 comment
Open

Add an escaper for the "hide link embed" markdown sequence #9852

janparisek opened this issue Sep 26, 2023 · 1 comment

Comments

@janparisek
Copy link
Contributor

Which application or package is this feature request for?

formatters

Feature

There's currently many Discord-flavored markdown sequences that can be escaped by the formatters @discordjs/formatters package. However, there's one sequence that's not supported yet: the "hide link embed" sequence.

This causes strings, such as <a:/b> to be rendered as a:/b by the Discord client.
The same goes for the intended purpose, of this sequence: <https://discord.js.org/> renders as https://discord.js.org/.

Escaping this sequence would cause text to render correctly.

Ideal solution or implementation

I propose a sophisticated approach to escape any occurrence of the pattern /<[^<>\s:]+:\/[^<>\s]+>/g by surrounding it between \< and >.

E.g. escaping <https://discord.js.org/> would result in the string \<<https://discord.js.org/>>.
This correctly renders as <https://discord.js.org/> in the Discord client while the link embed remains hidden.

Please note that this solution is not yet ideal, since there are very complex interactions between the <a:/b> sequence when they're being used in combination with masked links.

Alternative solutions or implementations

My original approach was simpler:
Escape any occurrence of the character < with \<. This works similar to how escapeStrikethrough() and escapeSpoiler() already work. However, this causes previously hidden link embeds to not be hidden anymore.
Therefore, this requires the MessageFlags.SuppressEmbeds to be set.

Other context

My personal use case is logging member nicknames. I noticed that a member had called themselves </:/:> while the message from the bot displayed their nickname as /:/: without the angled brackets.

Recreation of what it looked like:
image

@janparisek
Copy link
Contributor Author

I think I should mention that I already have two solutions ready since I needed a fix for my own bots.

However, I'd like to further discuss this topic here, for two reasons:

  • Is there even a need for a formatter?
  • If so, how sophisticated should it be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant