mirror of
https://github.com/zulip/zulip.git
synced 2025-11-21 15:09:34 +00:00
emoji: Migrate bugdown emoji to use sprite sheets.
This commit switches to use sprite sheets for rendering emojis in all the remaining places, i.e., message bodies and composebox typeahead. This commit also includes some changes to notifications.py file so that the spans used for rendering emojis can be converted to corresponding image tags so that we don't break the emoji rendering in missed message emails since we can't use sprite sheets there. As part of switching the bugdown system to use sprite sheets, we need to switch the name_to_codepoint mappings to match the new sprite sheets. This has the side effect of fixing a bunch of emoji like numbers and flag emoji in the emoji pickers. Fixes: #3895. Fixes: #3972.
This commit is contained in:
committed by
Tim Abbott
parent
d3bfc132fb
commit
5b5bcce098
@@ -89,11 +89,10 @@ def relative_to_full_url(base_url, content):
|
||||
content = re.sub(
|
||||
r"<img src=(\S+)/user_uploads/(\S+)>", "", content)
|
||||
|
||||
# URLs for emoji are of the form
|
||||
# "static/generated/emoji/images/emoji/snowflake.png".
|
||||
# Convert the zulip emoji's relative url to absolute one.
|
||||
content = re.sub(
|
||||
r"(?<=\=['\"])/static/generated/emoji/images/emoji/(?=[^<]+>)",
|
||||
base_url + r"/static/generated/emoji/images/emoji/",
|
||||
r"(?<=\=['\"])/static/generated/emoji/images/emoji/unicode/zulip.png(?=[^<]+>)",
|
||||
base_url + r"/static/generated/emoji/images/emoji/unicode/zulip.png",
|
||||
content)
|
||||
|
||||
# Realm emoji should use absolute URLs when referenced in missed-message emails.
|
||||
@@ -110,6 +109,18 @@ def relative_to_full_url(base_url, content):
|
||||
|
||||
return content
|
||||
|
||||
def fix_emojis(content, base_url):
|
||||
# type: (Text, Text) -> Text
|
||||
# Convert the emoji spans to img tags.
|
||||
content = re.sub(
|
||||
r'<span class=\"emoji emoji-(\S+)\" title=\"([^\"]+)\">(\S+)</span>',
|
||||
r'<img src="' + base_url + r'/static/generated/emoji/images-google-64/\1.png" ' +
|
||||
r'title="\2" alt="\3" style="height: 20px;">',
|
||||
content)
|
||||
content = content.replace(' class="emoji"', ' style="height: 20px;"')
|
||||
|
||||
return content
|
||||
|
||||
def build_message_list(user_profile, messages):
|
||||
# type: (UserProfile, List[Message]) -> List[Dict[str, Any]]
|
||||
"""
|
||||
@@ -133,10 +144,6 @@ def build_message_list(user_profile, messages):
|
||||
# with a simple hyperlink.
|
||||
return re.sub(r"\[(\S*)\]\((\S*)\)", r"\2", content)
|
||||
|
||||
def fix_emojis(html):
|
||||
# type: (Text) -> Text
|
||||
return html.replace(' class="emoji"', ' height="20px" style="position: relative;top: 6px;"')
|
||||
|
||||
def build_message_payload(message):
|
||||
# type: (Message) -> Dict[str, Text]
|
||||
plain = message.content
|
||||
@@ -153,7 +160,7 @@ def build_message_list(user_profile, messages):
|
||||
assert message.rendered_content is not None
|
||||
html = message.rendered_content
|
||||
html = relative_to_full_url(user_profile.realm.uri, html)
|
||||
html = fix_emojis(html)
|
||||
html = fix_emojis(html, user_profile.realm.uri)
|
||||
|
||||
return {'plain': plain, 'html': html}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user