Don't image-ify :( and other smileys 😞

(imported from commit 25323f19572c24da36267064a1ca820d80c9db79)
This commit is contained in:
Waseem Daher 2013-03-05 15:53:35 -05:00
parent 8160795cdc
commit 0dee6235cc
2 changed files with 3 additions and 57 deletions

View File

@ -86,39 +86,6 @@ class Gravatar(markdown.inlinepatterns.Pattern):
% (gravatar_hash(match.group('email')),))
return img
# We first map syntax of the form ":)" to the ":smile:" syntax, and
# then map syntax of the form ":foo:" to the emoji named "foo".
smiley_to_emoji = {
# We're somewhat restrained here, to avoid false positives
":-)" : "blush", # This is a very weird coopting of the blush emoticon, but the normal
":)" : "blush", # smile was so smiley that it became indistinguishable from grin.
":-(" : "worried",
":(" : "worried",
";-)" : "wink",
";)" : "wink",
":-P" : "stuck_out_tongue",
":-p" : "stuck_out_tongue",
":P" : "stuck_out_tongue",
":p" : "stuck_out_tongue",
":-*" : "kissing_closed_eyes",
":*" : "kissing_closed_eyes",
"8-)" : "sunglasses",
"8)" : "sunglasses",
"O:-)": "innocent",
"O:)" : "innocent",
"o:-)": "innocent",
"o:)" : "innocent",
":-/" : "confused",
":/" : "confused",
":'(" : "cry",
":-D" : "smiley",
":D" : "smiley",
":-|" : "expressionless",
":|" : "expressionless",
"<3" : "heart",
}
smiley_regex = '|'.join([re.escape(face) for face in smiley_to_emoji])
path_to_emoji = os.path.join(os.path.dirname(__file__), '..', '..',
# This should be zephyr/
'static', 'third', 'gemoji', 'images', 'emoji', '*.png')
@ -140,13 +107,6 @@ class Emoji(markdown.inlinepatterns.Pattern):
return orig_syntax
return make_emoji(name, orig_syntax)
class Smiley(markdown.inlinepatterns.Pattern):
def handleMatch(self, match):
orig_syntax = match.group("syntax")
if orig_syntax not in smiley_to_emoji:
return orig_syntax
return make_emoji(smiley_to_emoji[orig_syntax], orig_syntax)
def fixup_link(link):
"""Set certain attributes we want on every link."""
link.set('target', '_blank')
@ -303,7 +263,6 @@ class Bugdown(markdown.Extension):
md.inlinePatterns.add('gravatar', Gravatar(r'!gravatar\((?P<email>[^)]*)\)'), '_begin')
md.inlinePatterns.add('emoji', Emoji(r'(?<!\S)(?P<syntax>:[^:\s]+:)(?!\S)'), '_begin')
md.inlinePatterns.add('smileys', Smiley(r'(?<!\S)(?P<syntax>' + smiley_regex + r')(?!\S)'), '_begin')
md.inlinePatterns.add('link', LinkPattern(markdown.inlinepatterns.LINK_RE, md), '>backtick')
# markdown.inlinepatterns.Pattern compiles this with re.UNICODE, which

View File

@ -11,7 +11,7 @@ from zephyr.tornadoviews import json_get_updates, api_get_messages
from zephyr.decorator import RespondAsynchronously, RequestVariableConversionError
from zephyr.lib.initial_password import initial_password, initial_api_key
from zephyr.lib.actions import do_send_message, gather_subscriptions
from zephyr.lib.bugdown import convert, emoji_list, smiley_to_emoji
from zephyr.lib.bugdown import convert, emoji_list
import simplejson
import subprocess
@ -1954,26 +1954,13 @@ xxxxxxx</strong></p>\n<p>xxxxxxx xxxxx xxxx xxxxx:<br>\n<code>xxxxxx</code>: xxx
(':whale:', emoji_img(':whale:')),
(':fakeemoji:', ':fakeemoji:'),
(':even faker smile:', ':even faker smile:'),
# Smileys
(':)', emoji_img(':)', 'blush')),
(';)', emoji_img(';)', 'wink')),
('8)', emoji_img('8)', 'sunglasses')),
('o:)', emoji_img('o:)', 'innocent')),
('<3', emoji_img('&lt;3', 'heart')),
(':(', emoji_img(':(', 'worried')),
('x<3', 'x&lt;3')]
]
# Check every single emoji
for img in emoji_list:
emoji_text = ":%s:" % img
test_cases.append((emoji_text, emoji_img(emoji_text)))
# Check every single smiley
for smiley, emoji in smiley_to_emoji.iteritems():
# Fixup for <3
smiley_escaped_text = smiley.replace('<', '&lt;')
test_cases.append((smiley, emoji_img(smiley_escaped_text, emoji)))
for input, expected in test_cases:
self.assertEqual(convert(input), '<p>%s</p>' % expected)
@ -1981,7 +1968,7 @@ xxxxxxx</strong></p>\n<p>xxxxxxx xxxxx xxxx xxxxx:<br>\n<code>xxxxxx</code>: xxx
msg = 'test :smile: again :poop:\n:) foo:)bar x::y::z :wasted waste: :fakeemojithisshouldnotrender:'
converted = convert(msg)
self.assertEqual(converted, '<p>test ' + emoji_img(':smile:') + ' again ' + emoji_img(':poop:') + '<br>\n'
+ emoji_img(':)', 'blush') + ' foo:)bar x::y::z :wasted waste: :fakeemojithisshouldnotrender:</p>')
+ ':) foo:)bar x::y::z :wasted waste: :fakeemojithisshouldnotrender:</p>')
def test_multiline_strong(self):