-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,24 @@ | |
|
||
|
||
# constants | ||
emoji_unicodes = set(EMOJI_DATA.keys()) | ||
_defalut_twemoji_latest_version = "14.0.2" | ||
_str2emoji = {} | ||
_str2emoji_lang = {lang: {} for lang in LANGUAGES} | ||
for k, v in EMOJI_DATA.items(): | ||
if "status" in v and v["status"] > 2: | ||
# https://carpedm20.github.io/emoji/docs/api.html#emoji-status | ||
# 1: component, 2: fully-qualified, 3: minimally-qualified, 4: unqualified | ||
continue | ||
if "E" in v and str(v["E"]) > _defalut_twemoji_latest_version: | ||
# skip emoji with newer version than twemoji latest version | ||
continue | ||
# limit to unicode emoji with length <= 2 | ||
# longer emoji strings are usually composed of multiple unicode emoji | ||
if len(k) > 2: | ||
continue | ||
for key, s in v.items(): | ||
if key in ["status", "E", "variant"]: | ||
# "E" for Emoji version: https://carpedm20.github.io/emoji/docs/api.html#emoji-version | ||
continue | ||
if key == "alias": | ||
for alias in s: | ||
|
@@ -36,6 +48,7 @@ | |
_str2emoji[s] = k | ||
_str2emoji_lang[key][s] = k | ||
emoji_strs = set(_str2emoji.keys()) | ||
emoji_unicodes = set(_str2emoji.values()) | ||
|
||
|
||
def _url_is_reachable(url: str, timeout: float = 0.8) -> bool: | ||
|
@@ -70,7 +83,6 @@ def _get_twemoji_latest_version() -> str: | |
The latest twemoji version. | ||
""" | ||
defalut_latest_version = "14.0.2" | ||
url = "https://unpkg.com/twemoji@latest/dist/twemoji.min.js" | ||
try: | ||
r = requests.get(url, timeout=3) | ||
|
@@ -80,9 +92,9 @@ def _get_twemoji_latest_version() -> str: | |
# e.g. https://unpkg.com/[email protected]/dist/twemoji.min.js | ||
return re.search("twemoji@([\\w\\.\\-]+)", r.url).group(1) | ||
else: | ||
return defalut_latest_version | ||
return _defalut_twemoji_latest_version | ||
except Exception: | ||
return defalut_latest_version | ||
return _defalut_twemoji_latest_version | ||
|
||
|
||
def _get_twemoji_config(twemoji_assets_type: str = "72x72", twemoji_cdn: Optional[str] = None, **kwargs: Any) -> Dict[str, Any]: | ||
|
@@ -155,6 +167,8 @@ def _to_code_point(unicode_surrogates: str, sep: str = "-") -> str: | |
https://github.com/streamlit/streamlit/blob/develop/frontend/lib/src/vendor/twemoji.ts#L7-L24 | ||
https://unpkg.com/[email protected]/dist/twemoji.min.js | ||
Parameters | ||
---------- | ||
unicode_surrogates : str | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters