Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions emoji/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,12 @@ def handle(emoji_match: EmojiMatch) -> str:
else:
return ''
elif language in emoji_match.data:
if _use_aliases and 'alias' in emoji_match.data:
return (
delimiters[0] + emoji_match.data['alias'][0][1:-1] + delimiters[1]
)
if _use_aliases and 'alias' in emoji_match.data and emoji_match.data['alias']:
alias = emoji_match.data['alias'][0]
if len(alias) >= 2:
return delimiters[0] + alias[1:-1] + delimiters[1]
else:
return delimiters[0] + alias + delimiters[1]
else:
return delimiters[0] + emoji_match.data[language][1:-1] + delimiters[1]
else:
Expand Down Expand Up @@ -337,9 +339,8 @@ def handle(emoji_match: EmojiMatch) -> str:
return str(replace)
elif callable(replace):
return replace(emoji_match.emoji, emoji_match.data_copy())
elif replace is not None: # type: ignore
return replace
return emoji_match.emoji
else:
return str(replace) # This will convert empty string, None, or any other value to string

matches = tokenize(string, keep_zwj=config.replace_emoji_keep_zwj)
if config.replace_emoji_keep_zwj:
Expand Down Expand Up @@ -428,7 +429,7 @@ def version(string: str) -> float:
version: List[float] = []

def f(e: str, emoji_data: Dict[str, Any]) -> str:
version.append(emoji_data['E'])
version.append(emoji_data.get('E', 0.0)) # Default to 0.0 if 'E' key missing
return ''

replace_emoji(string, replace=f, version=-1)
Expand Down