mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
@@ -560,12 +560,19 @@ class Avatar(markdown.inlinepatterns.Pattern):
|
|||||||
if settings.VOYAGER:
|
if settings.VOYAGER:
|
||||||
path_to_emoji = os.path.join(os.path.dirname(__file__), '..', '..', '..',
|
path_to_emoji = os.path.join(os.path.dirname(__file__), '..', '..', '..',
|
||||||
'prod-static', 'serve', 'third', 'gemoji', 'images', 'emoji', '*.png')
|
'prod-static', 'serve', 'third', 'gemoji', 'images', 'emoji', '*.png')
|
||||||
|
path_to_unicode_emoji = os.path.join(os.path.dirname(__file__), '..', '..', '..',
|
||||||
|
'prod-static', 'serve', 'third', 'gemoji', 'images',
|
||||||
|
'emoji', 'unicode', '*.png')
|
||||||
else:
|
else:
|
||||||
path_to_emoji = os.path.join(os.path.dirname(__file__), '..', '..', '..',
|
path_to_emoji = os.path.join(os.path.dirname(__file__), '..', '..', '..',
|
||||||
# This should be the root
|
# This should be the root
|
||||||
'static', 'third', 'gemoji', 'images', 'emoji', '*.png')
|
'static', 'third', 'gemoji', 'images', 'emoji', '*.png')
|
||||||
|
path_to_unicode_emoji = os.path.join(os.path.dirname(__file__), '..', '..', '..',
|
||||||
|
# This should be the root
|
||||||
|
'static', 'third', 'gemoji', 'images', 'emoji', 'unicode', '*.png')
|
||||||
|
|
||||||
emoji_list = [os.path.splitext(os.path.basename(fn))[0] for fn in glob.glob(path_to_emoji)]
|
emoji_list = [os.path.splitext(os.path.basename(fn))[0] for fn in glob.glob(path_to_emoji)]
|
||||||
|
unicode_emoji_list = [os.path.splitext(os.path.basename(fn))[0] for fn in glob.glob(path_to_unicode_emoji)]
|
||||||
|
|
||||||
|
|
||||||
def make_emoji(emoji_name, src, display_string):
|
def make_emoji(emoji_name, src, display_string):
|
||||||
@@ -577,6 +584,17 @@ def make_emoji(emoji_name, src, display_string):
|
|||||||
elt.set("title", display_string)
|
elt.set("title", display_string)
|
||||||
return elt
|
return elt
|
||||||
|
|
||||||
|
class UnicodeEmoji(markdown.inlinepatterns.Pattern):
|
||||||
|
def handleMatch(self, match):
|
||||||
|
# type: (Match[text_type]) -> Optional[Element]
|
||||||
|
orig_syntax = match.group('syntax')
|
||||||
|
name = hex(ord(orig_syntax))[2:]
|
||||||
|
if name in unicode_emoji_list:
|
||||||
|
src = '/static/third/gemoji/images/emoji/unicode/%s.png' % (name)
|
||||||
|
return make_emoji(name, src, orig_syntax)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
class Emoji(markdown.inlinepatterns.Pattern):
|
class Emoji(markdown.inlinepatterns.Pattern):
|
||||||
def handleMatch(self, match):
|
def handleMatch(self, match):
|
||||||
# type: (Match[text_type]) -> Optional[Element]
|
# type: (Match[text_type]) -> Optional[Element]
|
||||||
@@ -940,6 +958,8 @@ class Bugdown(markdown.Extension):
|
|||||||
'_begin')
|
'_begin')
|
||||||
md.inlinePatterns.add('usermention', UserMentionPattern(mention.find_mentions), '>backtick')
|
md.inlinePatterns.add('usermention', UserMentionPattern(mention.find_mentions), '>backtick')
|
||||||
md.inlinePatterns.add('emoji', Emoji(r'(?<!\w)(?P<syntax>:[^:\s]+:)(?!\w)'), '_end')
|
md.inlinePatterns.add('emoji', Emoji(r'(?<!\w)(?P<syntax>:[^:\s]+:)(?!\w)'), '_end')
|
||||||
|
md.inlinePatterns.add('unicodeemoji', UnicodeEmoji(ur'(?<!\w)(?P<syntax>[\U0001F300-\U0001F64F\U0001F680-\U0001F6FF\u2600-\u26FF\u2700-\u27BF])(?!\w)'), '_end')
|
||||||
|
|
||||||
md.inlinePatterns.add('link', AtomicLinkPattern(markdown.inlinepatterns.LINK_RE, md), '>backtick')
|
md.inlinePatterns.add('link', AtomicLinkPattern(markdown.inlinepatterns.LINK_RE, md), '>backtick')
|
||||||
|
|
||||||
for (pattern, format_string) in self.getConfig("realm_filters"):
|
for (pattern, format_string) in self.getConfig("realm_filters"):
|
||||||
|
|||||||
@@ -331,6 +331,15 @@ class BugdownTest(TestCase):
|
|||||||
converted = bugdown.convert(":test:", "zulip.com", msg)
|
converted = bugdown.convert(":test:", "zulip.com", msg)
|
||||||
self.assertEqual(converted, '<p>:test:</p>')
|
self.assertEqual(converted, '<p>:test:</p>')
|
||||||
|
|
||||||
|
def test_unicode_emoji(self):
|
||||||
|
msg = u'\u2615' # ☕
|
||||||
|
converted = bugdown_convert(msg)
|
||||||
|
self.assertEqual(converted, u'<p><img alt="\u2615" class="emoji" src="/static/third/gemoji/images/emoji/unicode/2615.png" title="\u2615"></p>')
|
||||||
|
|
||||||
|
msg = u'\u2615\u2615' # ☕☕
|
||||||
|
converted = bugdown_convert(msg)
|
||||||
|
self.assertEqual(converted, u'<p><img alt="\u2615" class="emoji" src="/static/third/gemoji/images/emoji/unicode/2615.png" title="\u2615"><img alt="\u2615" class="emoji" src="/static/third/gemoji/images/emoji/unicode/2615.png" title="\u2615"></p>')
|
||||||
|
|
||||||
def test_realm_patterns(self):
|
def test_realm_patterns(self):
|
||||||
realm = get_realm('zulip.com')
|
realm = get_realm('zulip.com')
|
||||||
RealmFilter(realm=realm, pattern=r"#(?P<id>[0-9]{2,8})",
|
RealmFilter(realm=realm, pattern=r"#(?P<id>[0-9]{2,8})",
|
||||||
|
|||||||
Reference in New Issue
Block a user