Add test precise position for emojis

This commit is contained in:
Alexandre Mutel
2016-06-15 15:26:31 +09:00
parent 6f1d39e1bb
commit a9f33cbca6
2 changed files with 22 additions and 1 deletions

View File

@@ -360,6 +360,17 @@ literal ( 2, 5) 17-20
", "definitionlists");
}
[Test]
public void TestEmoji()
{
// 01 2345
Check("0\n :)\n", @"
paragraph ( 0, 0) 0-4
literal ( 0, 0) 0-0
linebreak ( 0, 1) 1-1
emoji ( 1, 1) 3-4
", "emojis");
}
private static void Check(string text, string expectedResult, string extensions = null)
{

View File

@@ -67,6 +67,7 @@ namespace Markdig.Extensions.Emoji
public override bool Match(InlineProcessor processor, ref StringSlice slice)
{
string match;
var startPosition = slice.Start;
if (!textMatchHelper.TryMatch(slice.Text, slice.Start, slice.Length, out match))
{
return false;
@@ -89,7 +90,16 @@ namespace Markdig.Extensions.Emoji
slice.Start += match.Length;
// Push the EmojiInline
processor.Inline = new EmojiInline(unicode) {Match = match};
int line;
int column;
processor.Inline = new EmojiInline(unicode)
{
SourceStartPosition = processor.GetSourcePosition(startPosition, out line, out column),
Line = line,
Column = column,
Match = match
};
processor.Inline.SourceEndPosition = processor.Inline.SourceStartPosition + match.Length - 1;
return true;
}