Skip to content

Commit 2b74788

Browse files
committed
Fix emoji not rendering in table cells
1 parent bddaa55 commit 2b74788

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/Markdig.Tests/TestCustomEmojis.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,20 @@ public void TestCustomEmojiValidation()
121121
smileyToEmoji.Add("a", "c"); // "a" already exists in emojiToUnicode
122122
Assert.Throws<ArgumentException>(() => new EmojiMapping(emojiToUnicode, smileyToEmoji));
123123
}
124+
125+
[Test]
126+
[TestCase("|test|\n|-|\n|:x:|", "<table>\n<thead>\n<tr>\n<th>test</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>❌</td>\n</tr>\n</tbody>\n</table>\n")]
127+
[TestCase("|test|\n|-|\n| :x: |", "<table>\n<thead>\n<tr>\n<th>test</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>❌</td>\n</tr>\n</tbody>\n</table>\n")]
128+
[TestCase("|test|\n|-|\n|1:x:|", "<table>\n<thead>\n<tr>\n<th>test</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>1:x:</td>\n</tr>\n</tbody>\n</table>\n")]
129+
[TestCase("|test|\n|-|\n|w:x:y|", "<table>\n<thead>\n<tr>\n<th>test</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>w:x:y</td>\n</tr>\n</tbody>\n</table>\n")]
130+
public void TestEmojiInPipeTable(string input, string expected)
131+
{
132+
var pipeline = new MarkdownPipelineBuilder()
133+
.UseEmojiAndSmiley()
134+
.UsePipeTables()
135+
.Build();
136+
137+
var actual = Markdown.ToHtml(input, pipeline);
138+
Assert.AreEqual(expected, actual);
139+
}
124140
}

src/Markdig/Extensions/Emoji/EmojiParser.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ public EmojiParser(EmojiMapping emojiMapping)
2929
/// </summary>
3030
public override bool Match(InlineProcessor processor, ref StringSlice slice)
3131
{
32-
// Previous char must be a space
33-
if (!slice.PeekCharExtra(-1).IsWhiteSpaceOrZero())
32+
// Previous char must be a space or non-alphanumeric.
33+
var prevChar = slice.PeekCharExtra(-1);
34+
if (!prevChar.IsWhiteSpaceOrZero() && char.IsLetterOrDigit(prevChar))
3435
{
3536
return false;
3637
}

0 commit comments

Comments
 (0)