-
-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #386 from mlaily/emoji-customization
Emojis and smileys customization
- Loading branch information
Showing
9 changed files
with
1,942 additions
and
1,773 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System.Collections.Generic; | ||
using Markdig.Extensions.Emoji; | ||
using NUnit.Framework; | ||
|
||
namespace Markdig.Tests | ||
{ | ||
[TestFixture] | ||
public class TestCustomEmojis | ||
{ | ||
[Test] | ||
[TestCase(":smiley:", "<p>♥</p>\n")] | ||
[TestCase(":confused:", "<p>:confused:</p>\n")] // default emoji does not work | ||
[TestCase(":/", "<p>:/</p>\n")] // default smiley does not work | ||
public void TestCustomEmoji(string input, string expected) | ||
{ | ||
var emojiToUnicode = new Dictionary<string, string>(); | ||
var smileyToEmoji = new Dictionary<string, string>(); | ||
|
||
emojiToUnicode[":smiley:"] = "♥"; | ||
|
||
var customMapping = new EmojiMapping(emojiToUnicode, smileyToEmoji); | ||
|
||
var pipeline = new MarkdownPipelineBuilder() | ||
.UseEmojiAndSmiley(customEmojiMapping: customMapping) | ||
.Build(); | ||
|
||
var actual = Markdown.ToHtml(input, pipeline); | ||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[Test] | ||
[TestCase(":testheart:", "<p>♥</p>\n")] | ||
[TestCase("hello", "<p>♥</p>\n")] | ||
[TestCase(":confused:", "<p>:confused:</p>\n")] // default emoji does not work | ||
[TestCase(":/", "<p>:/</p>\n")] // default smiley does not work | ||
public void TestCustomSmiley(string input, string expected) | ||
{ | ||
var emojiToUnicode = new Dictionary<string, string>(); | ||
var smileyToEmoji = new Dictionary<string, string>(); | ||
|
||
emojiToUnicode[":testheart:"] = "♥"; | ||
smileyToEmoji["hello"] = ":testheart:"; | ||
|
||
var customMapping = new EmojiMapping(emojiToUnicode, smileyToEmoji); | ||
|
||
var pipeline = new MarkdownPipelineBuilder() | ||
.UseEmojiAndSmiley(customEmojiMapping: customMapping) | ||
.Build(); | ||
|
||
var actual = Markdown.ToHtml(input, pipeline); | ||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[Test] | ||
[TestCase(":smiley:", "<p>♥</p>\n")] | ||
[TestCase(":)", "<p>♥</p>\n")] | ||
[TestCase(":confused:", "<p>😕</p>\n")] // default emoji still works | ||
[TestCase(":/", "<p>😕</p>\n")] // default smiley still works | ||
public void TestOverrideDefaultWithCustomEmoji(string input, string expected) | ||
{ | ||
var emojiToUnicode = EmojiMapping.GetDefaultEmojiShortcodeToUnicode(); | ||
var smileyToEmoji = EmojiMapping.GetDefaultSmileyToEmojiShortcode(); | ||
|
||
emojiToUnicode[":smiley:"] = "♥"; | ||
|
||
var customMapping = new EmojiMapping(emojiToUnicode, smileyToEmoji); | ||
|
||
var pipeline = new MarkdownPipelineBuilder() | ||
.UseEmojiAndSmiley(customEmojiMapping: customMapping) | ||
.Build(); | ||
|
||
var actual = Markdown.ToHtml(input, pipeline); | ||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[Test] | ||
[TestCase(":testheart:", "<p>♥</p>\n")] | ||
[TestCase("hello", "<p>♥</p>\n")] | ||
[TestCase(":confused:", "<p>😕</p>\n")] // default emoji still works | ||
[TestCase(":/", "<p>😕</p>\n")] // default smiley still works | ||
public void TestOverrideDefaultWithCustomSmiley(string input, string expected) | ||
{ | ||
var emojiToUnicode = EmojiMapping.GetDefaultEmojiShortcodeToUnicode(); | ||
var smileyToEmoji = EmojiMapping.GetDefaultSmileyToEmojiShortcode(); | ||
|
||
emojiToUnicode[":testheart:"] = "♥"; | ||
smileyToEmoji["hello"] = ":testheart:"; | ||
|
||
var customMapping = new EmojiMapping(emojiToUnicode, smileyToEmoji); | ||
|
||
var pipeline = new MarkdownPipelineBuilder() | ||
.UseEmojiAndSmiley(customEmojiMapping: customMapping) | ||
.Build(); | ||
|
||
var actual = Markdown.ToHtml(input, pipeline); | ||
Assert.AreEqual(expected, actual); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.