Beispiel #1
0
        public void GetText_ShouldReturnTextItself()
        {
            var text = "This is text sample";
            var node = new PlainTextNode(text);

            var actual = node.GetText();

            actual.Should().BeEquivalentTo(text);
        }
Beispiel #2
0
        public void GetText_WithoutItalicParent_ShouldReturnJoinedTextOfAllChildrenInStrongTag()
        {
            var plainText1 = new PlainTextNode(Text1);
            var plainText2 = new PlainTextNode(Text2);
            var bold       = new BoldNode();

            bold.AddNode(plainText1);
            bold.AddNode(plainText2);

            var actual = bold.GetText();

            actual.Should().BeEquivalentTo($"<strong>{Text1}{Text2}</strong>");
        }
        public override INode Parse(Parser parser, ParseData data, State state, string scope)
        {
            var index = state.Index;

            if (state.Next() != '[')
            {
                state.Seek(index, true);
                return(null);
            }

            var str = state.ScanTo("]");

            if (state.Next() != ']')
            {
                state.Seek(index, true);
                return(null);
            }

            var match = Regex.Match(str, @"^([a-z]{2,10}://[^\]]*?)(?:\|([^\]]*?))?$", RegexOptions.IgnoreCase);

            if (!match.Success)
            {
                state.Seek(index, true);
                return(null);
            }

            var url     = match.Groups[1].Value;
            var text    = match.Groups[2].Length > 0 ? match.Groups[2].Value : url;
            var options = new Dictionary <string, string> {
                { "url", url }
            };

            if (!Validate(options, text))
            {
                state.Seek(index, true);
                return(null);
            }

            url = System.Web.HttpUtility.HtmlAttributeEncode(url);
            var before = $"<{Element} href=\"{url}\">";
            var after  = $"</{Element}>";

            var content = new PlainTextNode(text);

            return(new HtmlNode(before, content, after)
            {
                PlainAfter = match.Groups[2].Length > 0 ? $" ({url})" : ""
            });
        }
Beispiel #4
0
        public void GetText_WithItalicParent_ShouldReturnJoinedTextOfAllChildren()
        {
            var italic     = new ItalicNode();
            var plainText1 = new PlainTextNode(Text1);
            var plainText2 = new PlainTextNode(Text2);
            var bold       = new BoldNode();

            bold.AddNode(plainText1);
            bold.AddNode(plainText2);
            italic.AddNode(bold);

            var actual = bold.GetText();

            actual.Should().BeEquivalentTo(Text1 + Text2);
        }
Beispiel #5
0
        public void GetText_ShouldReturnJoinedTextsOfAllChildren()
        {
            var root   = new RootNode();
            var bold   = new BoldNode();
            var italic = new ItalicNode();
            var plain  = new PlainTextNode("Text");

            bold.AddNode(new PlainTextNode("Bold"));
            italic.AddNode(new PlainTextNode("Italic"));
            root.AddNode(plain);
            root.AddNode(bold);
            root.AddNode(italic);

            var actual = root.GetText();

            actual.Should().BeEquivalentTo($"{plain.GetText()}{bold.GetText()}{italic.GetText()}");
        }