예제 #1
0
        public string Render(string paragraph)
        {
            var markdownTokens = TextToTokensParser.Parse(paragraph);

            MarkdownToHtmlParser.Parse(markdownTokens, tagsCollection);
            var stringBuilder = new StringBuilder(paragraph);
            var delta         = 0;

            foreach (var markdownToken in markdownTokens.OrderBy(t => t.Start))
            {
                stringBuilder.Replace(markdownToken.Line, tagsCollection[markdownToken].Line, markdownToken
                                      .Start + delta, markdownToken.Length);
                delta += tagsCollection[markdownToken].Length - markdownToken.Length;
            }

            for (int i = 0; i <= stringBuilder.Length - 1; i++)
            {
                if (stringBuilder[i] == '\\')
                {
                    stringBuilder.Remove(i, 1);
                }
            }

            return(stringBuilder.ToString());
        }
예제 #2
0
        public void Parser_Should_ParseTokensCorrectly(TextParserSource.TextParserData data)
        {
            var text           = data.Text;
            var expectedResult = data.Result;
            var result         = TextToTokensParser.Parse(text);

            result.Select(t => t.Line)
            .ToList()
            .Should()
            .BeEquivalentTo(expectedResult);
        }