Example #1
0
        public virtual IHtmlElement Create(HtmlAttributesCollection attributes, string html, int startContentIndex, int endContentIndex, IHtmlParserManager htmlParserManager)
        {
            HtmlPairTagsElement element = (HtmlPairTagsElement)CreateInstance();

            element.Attributes = attributes;
            element.Text(html.SubStringToIndex(startContentIndex, endContentIndex - 1));
            return(element);
        }
        public void ParseString_ReturnScriptElement_WhenHaveJavaScript(string html)
        {
            // Arrange

            // Act
            HtmlPairTagsElement element = (HtmlPairTagsElement)htmlParser.ParseString(html).FirstOrDefault();

            // Assert
            Assert.NotNull(element);
            Assert.Equal("function myFunction() { var $template = \"<button type=\"button\" onclick=\"myFunction()\">Try it</button>\" var $div = $(<div>); $div.append('<span />');  document.getElementById(\"demo\").innerHTML = \"Paragraph changed.\"; }", element.Text().ToString());
        }
Example #3
0
        public void Create_ReturnTagAsHtmlString_WhenTagIsHaveText()
        {
            // Arrange
            htmlBuilder = new HtmlBuilder();

            HtmlElement htmlTag = new HtmlPairTagsElement("div", "Text");

            // Act
            IHtmlContent result = htmlBuilder.CreateHtmlContent(htmlTag);

            // Assert
            Assert.Equal("<div>Text</div>", result.ToString());
        }
        private HtmlNodeElement GetSelect(string name, IEnumerable <SelectListItem> values, string value, bool isMultiple = false)
        {
            HtmlNodeElement select = new HtmlNodeElement("select");

            select.AddAttribute(new HtmlNameAttribute(name));
            if (isMultiple)
            {
                select.AddAttribute("multiple");
            }

            if (_options.InputAttributes != null)
            {
                select.AddRangeAttributes(_options.InputAttributes);
            }

            foreach (var item in values)
            {
                var option = new HtmlPairTagsElement("option")
                {
                    Attributes = new IHtmlAttribute[]
                    {
                        new HtmlAttribute("value", item.Value)
                    }
                };

                option.Text(new HtmlString(item.Text));

                if (item.Selected || (value != null && item.Value == value.ToString()))
                {
                    option.AddAttribute("selected");
                }

                select.Append(option);
            }

            return(select);
        }
Example #5
0
 /// <summary>
 /// Create html content.
 /// </summary>
 /// <param name="htmlElement">Object of type HtmlPairTagsElement, for convert to standart HTML pair tags content.</param>
 /// <returns>Html content repsresent specified pair tags element.</returns>
 public IHtmlContent CreateHtmlContent(HtmlPairTagsElement htmlElement)
 {
     return(new HtmlString(
                $"{CreateStartTag(htmlElement.TagName)}{htmlElement.Text()}{CreateEndTag(htmlElement.TagName)}"
                .Insert((htmlElement.TagName.Length + 1), htmlElement.Attributes.IsNullOrEmpty() ? "" : $" {String.Join(" ", htmlElement.Attributes.Select(x => CreateAtribute(x)))}")));
 }