-
Notifications
You must be signed in to change notification settings - Fork 288
Description
Not really a bug, more an observation:
When using emoji.replace_emoji(str, '') to strip emoji from a string, it also replaces all text emoji. This might not be the expected behavior by the user.
For example:
> emoji.replace_emoji("pure emoji 😁 text variant © emoji variant ©️", "?")
pure emoji ? text variant ? emoji variant ?So the © get removed, even though it is in text-variant. If someone is trying to remove emoji from a string, then they might not want to remove these symbols like © ® ↔
However several of these text-emoji are represented as text in one font and as emoji in another font.
For example as I am writing this issue, the :right_arrow: \u27a1 ➡ is represented as a text emoji in Github's text editor, but it will be displayed as a emoji when the issue appears online.
(it still can be forced to text with the text-variant selector: \u27a1\ufe0e ➡︎ )
I don't see a solution to this, but the behaviour should be mentioned in the documentation.
One option for some users could be to replace emoji, but keep emoji with text-variant and force the text-variant by appending \uFE0E (text variant selector):
import emoji
def repl(e, d):
if 'variant' in d and not e.endswith('\uFE0F'):
# Emoji supports variants and emoji-variant (\uFE0F) is not selected
if e.endswith('\uFE0E'):
# Emoji is already in text-variant
return e
else:
# Emoji is not in text-variant, add text-variant selector
return e + '\uFE0E'
else:
# Emoji doesn't support variants, or emoji-variant is selected
return ''
emoji.replace_emoji("smile 😁. copyright ©. Arrow-no-variant ➡.", repl)Input is: "smile 😁. copyright ©. Arrow-no-variant ➡."
Output is: "smile . copyright ©︎. Arrow-no-variant ➡︎."