emoji: Fix a bug where emoticon translation is not done after a newline.

This bug is caused by the conversion of newlines to `<br>` statements,
since `>` is not allowed as a character around an emoticon during
translation.

Also, add a new test case for preventing this bug from occurring in the
future.

Fix #9763.
This commit is contained in:
Marco Burstein 2018-06-20 08:09:18 -07:00 committed by Tim Abbott
parent 00c5afb491
commit 02489e5fb8
2 changed files with 8 additions and 1 deletions

View File

@ -1560,7 +1560,7 @@ class Bugdown(markdown.Extension):
'tex',
Tex(r'\B(?<!\$)\$\$(?P<body>[^\n_$](\\\$|[^$\n])*)\$\$(?!\$)\B'),
'>backtick')
md.inlinePatterns.add('emoji', Emoji(EMOJI_REGEX), '_end')
md.inlinePatterns.add('emoji', Emoji(EMOJI_REGEX), '<nl')
md.inlinePatterns.add('translate_emoticons', EmoticonTranslation(emoticon_regex), '>emoji')
md.inlinePatterns.add('unicodeemoji', UnicodeEmoji(unicode_emoji_regex), '_end')
md.inlinePatterns.add('link', AtomicLinkPattern(markdown.inlinepatterns.LINK_RE, md), '>avatar')

View File

@ -384,6 +384,13 @@
"text_content": "a:) ;)b",
"translate_emoticons": true
},
{
"name": "translate_emoticons_newline",
"input": ":) test\n:) test",
"expected_output": "<p><span class=\"emoji emoji-1f603\" title=\"smiley\">:smiley:</span> test<br>\n<span class=\"emoji emoji-1f603\" title=\"smiley\">:smiley:</span> test</p>",
"text_content": "\ud83d\ude03 test\n\ud83d\ude03 test",
"translate_emoticons": true
},
{
"name": "translate_emoticons_in_code",
"input": "`:)`",