예제 #1
0
        public void CorrectRendering_WhenRenderHeaderTag()
        {
            var line   = "#kek";
            var render = new TextRender(Utils.GetAllAvailableRules());
            var parsed = new List <ParsedSubline>()
            {
                new ParsedSubline(0, 4, Utils.GetAllAvailableRules().First(e => e.MarkupTag == "#"))
            };

            var actual = render.RenderLine(line, parsed);

            actual.Should().Be("<h1>kek</h1>");
        }
예제 #2
0
        public void CorrectRendering_WhenNestingTagsInLine()
        {
            var line      = "#_a_";
            var headerTag = new ParsedSubline(0, line.Length, new Header());
            var boldTag   = new ParsedSubline(1, 3, new Cursive());
            var parsed    = new List <ParsedSubline>()
            {
                headerTag, boldTag
            };

            var render = new TextRender(Utils.GetAllAvailableRules());
            var result = render.RenderLine(line, parsed);

            result.Should().BeEquivalentTo("<h1><em>a</em></h1>");
        }
예제 #3
0
        public void CorrectRending_WhenNeedsRenderingOneTag(string line, string markupTag,
                                                            int leftBorderOfSubline, int rightBorderOfSubline, string expected)
        {
            var render = new TextRender(Utils.GetAllAvailableRules());
            var parsed = new List <ParsedSubline>()
            {
                new ParsedSubline(leftBorderOfSubline, rightBorderOfSubline,
                                  Utils.GetAllAvailableRules().First(e => e.MarkupTag == markupTag)),
                new ParsedSubline(-1, line.Length, new Paragraph())
            };

            var actual = render.RenderLine(line, parsed);

            actual.Should().Be(expected);
        }
예제 #4
0
        public string RenderToHtml(string markdown)
        {
            var result = new StringBuilder();
            var parser = new TextParser(CurrentMarkupRules);
            var render = new TextRender(CurrentMarkupRules);

            foreach (var line in markdown.Split(new string[] { "\n\n" }, StringSplitOptions.RemoveEmptyEntries))
            {
                var newLine  = EscapeSpecialSymbols(line);
                var parsed   = parser.ParseLine(newLine);
                var rendered = render.RenderLine(newLine, parsed);
                result.Append($"{rendered}\n");
            }
            return(result.ToString());
        }
예제 #5
0
        public void CorrectRendering_WhenFewTagsInLine()
        {
            var line         = "_a_ __b__";
            var cursiveTag   = new ParsedSubline(0, 2, new Cursive());
            var boldTag      = new ParsedSubline(4, 7, new Bold());
            var paragraphTag = new ParsedSubline(-1, line.Length, new Paragraph());
            var parsed       = new List <ParsedSubline>()
            {
                cursiveTag, boldTag, paragraphTag
            };

            var render = new TextRender(Utils.GetAllAvailableRules());
            var result = render.RenderLine(line, parsed);

            result.Should().BeEquivalentTo("<p><em>a</em> <strong>b</strong></p>");
        }