mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	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:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							c14cefc24c
						
					
				
				
					commit
					a3ed83f4e2
				
			@@ -381,6 +381,21 @@
 | 
				
			|||||||
      "text_content": ":)",
 | 
					      "text_content": ":)",
 | 
				
			||||||
      "translate_emoticons": true
 | 
					      "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",
 | 
					      "name": "random_emoji_1",
 | 
				
			||||||
      "input": ":airplane:",
 | 
					      "input": ":airplane:",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,7 +28,10 @@ EMOTICON_CONVERSIONS = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
possible_emoticons = EMOTICON_CONVERSIONS.keys()
 | 
					possible_emoticons = EMOTICON_CONVERSIONS.keys()
 | 
				
			||||||
possible_emoticon_regexes = map(re.escape, possible_emoticons)  # type: ignore # AnyStr/str issues
 | 
					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:`.
 | 
					# Translates emoticons to their colon syntax, e.g. `:smiley:`.
 | 
				
			||||||
def translate_emoticons(text: Text) -> Text:
 | 
					def translate_emoticons(text: Text) -> Text:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user