From 6bc0eb4b1c17f5bad6fb9e8b2dea0587432ef299 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 20 Mar 2024 10:48:17 -0500 Subject: [PATCH] Wrap space around emoji regex --- judge/markdown_extensions/emoticon.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/judge/markdown_extensions/emoticon.py b/judge/markdown_extensions/emoticon.py index 4ea8e18..809b1d3 100644 --- a/judge/markdown_extensions/emoticon.py +++ b/judge/markdown_extensions/emoticon.py @@ -103,9 +103,10 @@ class EmoticonEmojiInlineProcessor(InlineProcessor): class EmoticonExtension(Extension): def extendMarkdown(self, md): - # Create the regex pattern to match any emoticon in the map emoticon_pattern = ( + r"(?:(?<=\s)|^)" # Lookbehind for a whitespace character or the start of the string r"(" + "|".join(map(re.escape, EMOTICON_EMOJI_MAP.keys())) + r")" + r"(?=\s|$)" # Lookahead for a whitespace character or the end of the string ) emoticon_processor = EmoticonEmojiInlineProcessor(emoticon_pattern, md) md.inlinePatterns.register(emoticon_processor, "emoticon_to_emoji", 1)