markdown: Update bugdown emoticon translation logic to match frontend.

This PR solves some of the parity issues in the emoticon translation
logic. I was unable to find a way of matching only one of the
lookaround groups, so we still have some inconsistency (see
testcase). The approach of having another check while converting just
for this seemed like an inefficient way, so I've left that last change
as it is.
This commit is contained in:
Rohitt Vashishtha
2018-03-30 04:04:25 +05:30
committed by Tim Abbott
parent c14cefc24c
commit a3ed83f4e2
2 changed files with 19 additions and 1 deletions

View File

@@ -381,6 +381,21 @@
"text_content": ":)",
"translate_emoticons": true
},
{
"name": "translate_emoticons_at_sentence_end",
"input": "Translate this :).",
"expected_output": "<p>Translate this <span class=\"emoji emoji-1f603\" title=\"smiley\">:smiley:</span>.</p>",
"text_content": "Translate this \ud83d\ude03.",
"translate_emoticons": true
},
{
"name": "translate_emoticons_between_symbols",
"input": "Translate this !:)?",
"expected_output": "<p>Translate this !<span class=\"emoji emoji-1f603\" title=\"smiley\">:smiley:</span>?</p>",
"marked_expected_output": "<p>Translate this !:)?</p>",
"text_content": "Translate this !\ud83d\ude03?",
"translate_emoticons": true
},
{
"name": "random_emoji_1",
"input": ":airplane:",

View File

@@ -28,7 +28,10 @@ EMOTICON_CONVERSIONS = {
possible_emoticons = EMOTICON_CONVERSIONS.keys()
possible_emoticon_regexes = map(re.escape, possible_emoticons) # type: ignore # AnyStr/str issues
emoticon_regex = '(?<![^\s])(?P<emoticon>(' + ')|('.join(possible_emoticon_regexes) + '))(?![\S])' # type: ignore # annoying
terminal_symbols = ',.;?!()\\[\\] "\'\\n\\t' # type: str # from composebox_typeahead.js
emoticon_regex = ('(?<![^{0}])(?P<emoticon>('.format(terminal_symbols)
+ ')|('.join(possible_emoticon_regexes) # type: ignore # AnyStr/str issues
+ '))(?![^{0}])'.format(terminal_symbols))
# Translates emoticons to their colon syntax, e.g. `:smiley:`.
def translate_emoticons(text: Text) -> Text: