public void DivInsidePAndB() { string html = "<div><p>one</p></div><b></b>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); Assert.IsNotNull(parser.Current); TestUtility.AreEqual(parser.Current, "div", "<p>one</p>", "<div><p>one</p></div>"); Assert.IsTrue(parser.Current.HasChildren); Assert.AreEqual(1, parser.Current.Children.Count()); Assert.IsNotNull(parser.Current.Children.ElementAt(0)); TestUtility.AreEqual(parser.Current.Children.ElementAt(0), "p", "one", "<p>one</p>"); Assert.IsNull(parser.Current.Children.ElementAt(0).Previous); Assert.IsNull(parser.Current.Children.ElementAt(0).Next); Assert.IsNull(parser.Current.Previous); Assert.IsNotNull(parser.Current.Next); TestUtility.AreEqual(parser.Current.Next, "b", "", "<b></b>"); Assert.IsNull(parser.Current.Next.Next); Assert.IsNotNull(parser.Current.Next.Previous); Assert.AreEqual(parser.Current, parser.Current.Next.Previous); Assert.IsFalse(parser.Parse()); }
public void SingleNode() { string html = "<div></div>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); Assert.IsNotNull(parser.Current); TestUtility.AreEqual(parser.Current, "div", "", html); Assert.IsNull(parser.Current.Previous); Assert.IsNull(parser.Current.Next); Assert.IsFalse(parser.Parse()); }
public void MultiLayerWithNoInheritance() { string html = "<div style='font-family:arial;width:10px'><div><span>test</span></div></div>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; node.AnalyzeNode("div", "<div><span>test</span></div>", html, null, false, true, 1, 1, 2); node.Attributes.CheckKeyValuePair(0, "style", "font-family:arial;width:10px"); node.Styles.CheckKeyValuePair(0, "font-family", "arial"); node.Styles.CheckKeyValuePair(1, "width", "10px"); node.Children.ElementAt(0).AnalyzeNode("div", "<span>test</span>", "<div><span>test</span></div>", node, false, true, 1, 0, 0); Assert.AreEqual(1, node.Children.ElementAt(0).InheritedStyles.Count); node.Children.ElementAt(0).CheckInheritedStyle(0, "font-family", "arial"); node.Children.ElementAt(0).Children.ElementAt(0).AnalyzeNode("span", "test", "<span>test</span>", node.Children.ElementAt(0), false, true, 1, 0, 0); Assert.AreEqual(1, node.Children.ElementAt(0).Children.ElementAt(0).InheritedStyles.Count); node.Children.ElementAt(0).Children.ElementAt(0).CheckInheritedStyle(0, "font-family", "arial"); }
public void CommentWithMediaQuery() { string path = TestUtility.GetFolderPath("Html\\commentwithmediaquery.htm"); string html = string.Empty; using (StreamReader sr = new StreamReader(path)) { html = sr.ReadToEnd(); } HtmlParser parser = new HtmlTextParser(html); Assert.AreEqual(true, parser.Parse()); parser.ParseStyles(); IHtmlNode node = parser.Current; while (node.Tag != "html") node = node.Next; node = node.Children.ElementAt(0); while (node.Tag != "body") node = node.Next; IHtmlNode body=node; node = node.Children.ElementAt(0); while (node.Tag != "p") node = node.Next; TestUtility.AnalyzeNode(node, "p", "test", "<p>test</p>", body, false, true, 1, 0, 0); }
public IHtmlNode FindBodyOrFirstElement() { MariGold.HtmlParser.HtmlParser parser = new HtmlTextParser(html); parser.UriSchema = uriSchema; parser.BaseURL = baseUrl; parser.Parse(); parser.ParseStyles(); IHtmlNode node = parser.Current; IHtmlNode body = null; while (node != null) { body = FindBody(node); if (body != null || node.Next == null) { break; } node = node.Next; } return body ?? parser.Current; }
public void FontSizeLineHeightFontFamily() { string html = "<div style='font:25px/2pt arial'><div style='font-family:verdana'>test</div></div>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); IHtmlNode node = parser.Current; Assert.IsNotNull(node); TestUtility.AnalyzeNode(node, "div", "<div style='font-family:verdana'>test</div>", html, null, false, true, 1, 1, 3); node.CheckStyle(0, "font-size", "25px"); node.CheckStyle(1, "line-height", "2pt"); node.CheckStyle(2, "font-family", "arial"); IHtmlNode parent = node; node = node.Children.ElementAt(0); Assert.IsNotNull(node); TestUtility.AnalyzeNode(node, "div", "test", "<div style='font-family:verdana'>test</div>", parent, false, true, 1, 1, 1); node.CheckStyle(0, "font-family", "verdana"); Assert.AreEqual(3, node.InheritedStyles.Count); node.CheckInheritedStyle(0, "font-size", "25px"); node.CheckInheritedStyle(1, "line-height", "2pt"); node.CheckInheritedStyle(2, "font-family", "verdana"); }
public void ClassAttribute() { string html = @"<style> .cls { color:red; } [attr] { color:blue; } </style> <div class='cls' attr></div>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; while (node.Tag != "div") { node = node.Next; } TestUtility.AnalyzeNode(node, "div", "", "<div class='cls' attr></div>", null, false, false, 0, 2, 1); TestUtility.CheckKeyValuePair(node.Attributes.ElementAt(0), "class", "cls"); TestUtility.CheckKeyValuePair(node.Attributes.ElementAt(1), "attr", ""); TestUtility.CheckKeyValuePair(node.Styles.ElementAt(0), "color", "blue"); }
public void DivAndP() { string html = "<div>test</div><p>one</p>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); Assert.IsNotNull(parser.Current); TestUtility.AreEqual(parser.Current, "div", "test", "<div>test</div>"); Assert.IsNull(parser.Current.Previous); Assert.IsNotNull(parser.Current.Next); TestUtility.AreEqual(parser.Current.Next, "p", "one", "<p>one</p>"); Assert.IsNotNull(parser.Current.Next.Previous); Assert.AreEqual(parser.Current, parser.Current.Next.Previous); Assert.IsNull(parser.Current.Next.Next); Assert.IsFalse(parser.Parse()); }
public void InputWithEmptyQuote() { string html = "<input \"\" />"; HtmlParser parser = new HtmlTextParser(html); Assert.AreEqual(true, parser.Parse()); Assert.IsNotNull(parser.Current); parser.Current.AnalyzeNode("input", html, html, null, true, false, 0, 0, 0); }
public void InvalidQuote() { string html = "<div style=\"width:100%\" \">test</div>"; HtmlParser parser = new HtmlTextParser(html); Assert.AreEqual(true, parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); parser.Current.AnalyzeNode("div", "test", html, null, false, true, 1, 1, 1); }
public void InvalidInputAttribute() { string html = "<input =\"\" name=\"fld_quicksign\">"; HtmlParser parser = new HtmlTextParser(html); Assert.AreEqual(true, parser.Parse()); Assert.IsNotNull(parser.Current); Assert.AreEqual(1, parser.Current.Attributes.Count); TestUtility.CheckKeyValuePair(parser.Current.Attributes.ElementAt(0), "name", "fld_quicksign"); }
public void EmptyHtml() { string html = " "; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); Assert.IsNotNull(parser.Current); TestUtility.AreEqual(parser.Current, "#text", html, html); Assert.IsNull(parser.Current.Previous); Assert.IsNull(parser.Current.Next); }
public void CommentWithoutSpace() { string html = @"<style>/*styles*/.cls{color:red;}</style> <div class='cls'>test</div>"; HtmlParser parser = new HtmlTextParser(html); Assert.AreEqual(true, parser.Parse()); parser.ParseStyles(); IHtmlNode node = parser.Current; while (node.Tag != "div") node = node.Next; TestUtility.AnalyzeNode(node, "div", "test", "<div class='cls'>test</div>", null, false, true, 1, 1, 1); node.CheckStyle(0, "color", "red"); }
public void FontSizeOnly() { string html = "<div style='font:25px'><div style='font-family:verdana'>test</div></div>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); IHtmlNode node = parser.Current; Assert.IsNotNull(node); TestUtility.AnalyzeNode(node, "div", "<div style='font-family:verdana'>test</div>", html, null, false, true, 1, 1, 1); node.CheckStyle(0, "font", "25px"); IHtmlNode parent = node; node = node.Children.ElementAt(0); Assert.IsNotNull(node); TestUtility.AnalyzeNode(node, "div", "test", "<div style='font-family:verdana'>test</div>", parent, false, true, 1, 1, 1); node.CheckStyle(0, "font-family", "verdana"); }
public void BasicInheritance() { string html = "<div style='font-family:arial'><div>test</div></div>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; node.AnalyzeNode("div", "<div>test</div>", html, null, false, true, 1, 1, 1); node.Attributes.CheckKeyValuePair(0, "style", "font-family:arial"); node.Styles.CheckKeyValuePair(0, "font-family", "arial"); node.Children.ElementAt(0).AnalyzeNode("div", "test", "<div>test</div>", node, false, true, 1, 0, 0); Assert.AreEqual(1, node.Children.ElementAt(0).InheritedStyles.Count); node.Children.ElementAt(0).InheritedStyles.CheckKeyValuePair(0, "font-family", "arial"); }
public void AttributeImmediateChildrenClassIdentityNthChild() { string html = @"<style> [attr] > .cls #pt:nth-child(2) { background-color:red; } </style> <div attr><div class='cls'><p>one1</p><p id='pt'>one2</p></div><div>two</div></div>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; while (node.Tag != "div") { node = node.Next; } TestUtility.AnalyzeNode(node, "div", "<div class='cls'><p>one1</p><p id='pt'>one2</p></div><div>two</div>", "<div attr><div class='cls'><p>one1</p><p id='pt'>one2</p></div><div>two</div></div>", null, false, true, 2, 1, 0); TestUtility.CheckKeyValuePair(node.Attributes.ElementAt(0), "attr", ""); TestUtility.AnalyzeNode(node.Children.ElementAt(0), "div", "<p>one1</p><p id='pt'>one2</p>", "<div class='cls'><p>one1</p><p id='pt'>one2</p></div>", node, false, true, 2, 1, 0); TestUtility.CheckKeyValuePair(node.Children.ElementAt(0).Attributes.ElementAt(0), "class", "cls"); TestUtility.AnalyzeNode(node.Children.ElementAt(0).Children.ElementAt(0), "p", "one1", "<p>one1</p>", node.Children.ElementAt(0), false, true, 1, 0, 0); TestUtility.AnalyzeNode(node.Children.ElementAt(0).Children.ElementAt(1), "p", "one2", "<p id='pt'>one2</p>", node.Children.ElementAt(0), false, true, 1, 1, 1); TestUtility.CheckKeyValuePair(node.Children.ElementAt(0).Children.ElementAt(1).Attributes.ElementAt(0), "id", "pt"); TestUtility.CheckKeyValuePair(node.Children.ElementAt(0).Children.ElementAt(1).Styles.ElementAt(0), "background-color", "red"); TestUtility.AnalyzeNode(node.Children.ElementAt(1), "div", "two", "<div>two</div>", node, false, true, 1, 0, 0); }
public void InputWithEmptyValue() { string html = "<div><input value=\"\" /><div style=\"width:100%\">1</div></div>"; HtmlParser parser = new HtmlTextParser(html); Assert.AreEqual(true, parser.Parse()); parser.ParseStyles(); IHtmlNode node = parser.Current; Assert.IsNotNull(node); node.AnalyzeNode("div", "<input value=\"\" /><div style=\"width:100%\">1</div>", html, null, false, true, 2, 0, 0); IHtmlNode parent = node; node = node.Children.ElementAt(0); Assert.IsNotNull(node); node.AnalyzeNode("input", "<input value=\"\" />", "<input value=\"\" />", parent, true, false, 0, 1, 0); node = parent.Children.ElementAt(1); Assert.IsNotNull(node); node.AnalyzeNode("div", "1", "<div style=\"width:100%\">1</div>", parent, false, true, 1, 1, 1); }
public void IdentityChildrenClass() { string html = @"<style> #dv .cls { color:#fff; background-color:#000; } </style> <div id='dv'><div class='cls'>one</div></div>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; while (node != null) { if (node.Tag == "div") { TestUtility.AnalyzeNode(node, "div", "<div class='cls'>one</div>", "<div id='dv'><div class='cls'>one</div></div>", null, false, true, 1, 1, 0); TestUtility.CheckKeyValuePair(node.Attributes.ElementAt(0), "id", "dv"); TestUtility.AnalyzeNode(node.Children.ElementAt(0), "div", "one", "<div class='cls'>one</div>", node, false, true, 1, 1, 2); TestUtility.CheckKeyValuePair(node.Children.ElementAt(0).Attributes.ElementAt(0), "class", "cls"); TestUtility.CheckKeyValuePair(node.Children.ElementAt(0).Styles.ElementAt(0), "color", "#fff"); TestUtility.CheckKeyValuePair(node.Children.ElementAt(0).Styles.ElementAt(1), "background-color", "#000"); } node = node.Next; } }
public void DivPB() { string html = "<div></div><p></p><b></b>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); Assert.IsNotNull(parser.Current); TestUtility.AreEqual(parser.Current, "div", "", "<div></div>"); Assert.IsNull(parser.Current.Previous); Assert.IsNotNull(parser.Current.Next); TestUtility.AreEqual(parser.Current.Next, "p", "", "<p></p>"); Assert.IsNotNull(parser.Current.Next.Previous); Assert.IsNotNull(parser.Current.Next.Next); Assert.AreEqual(parser.Current, parser.Current.Next.Previous); Assert.IsNotNull(parser.Current.Next.Next); TestUtility.AreEqual(parser.Current.Next.Next, "b", "", "<b></b>"); Assert.IsNull(parser.Current.Next.Next.Next); Assert.IsNotNull(parser.Current.Next.Next.Previous); Assert.AreEqual(parser.Current.Next, parser.Current.Next.Next.Previous); Assert.AreEqual(parser.Current, parser.Current.Next.Next.Previous.Previous); Assert.IsFalse(parser.Parse()); }
public void ClassDivImmediatePs() { string html = @"<style> .cls > p { font-weight:bold; } </style> <div class='cls'><p>new</p><div><p>one</p></div><p>two</p></div>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; while (node.Tag != "div") { node = node.Next; } TestUtility.AnalyzeNode(node, "div", "<p>new</p><div><p>one</p></div><p>two</p>", "<div class='cls'><p>new</p><div><p>one</p></div><p>two</p></div>", null, false, true, 3, 1, 0); TestUtility.CheckKeyValuePair(node.Attributes.ElementAt(0), "class", "cls"); TestUtility.AnalyzeNode(node.Children.ElementAt(0), "p", "new", "<p>new</p>", node, false, true, 1, 0, 1); TestUtility.CheckKeyValuePair(node.Children.ElementAt(0).Styles.ElementAt(0), "font-weight", "bold"); TestUtility.AnalyzeNode(node.Children.ElementAt(1), "div", "<p>one</p>", "<div><p>one</p></div>", node, false, true, 1, 0, 0); TestUtility.AnalyzeNode(node.Children.ElementAt(1).Children.ElementAt(0), "p", "one", "<p>one</p>", node.Children.ElementAt(1), false, true, 1, 0, 0); TestUtility.AnalyzeNode(node.Children.ElementAt(1).Children.ElementAt(0).Children.ElementAt(0), "#text", "one", "one", node.Children.ElementAt(1).Children.ElementAt(0), false, false, 0, 0, 0); TestUtility.AnalyzeNode(node.Children.ElementAt(2), "p", "two", "<p>two</p>", node, false, true, 1, 0, 1); TestUtility.CheckKeyValuePair(node.Children.ElementAt(2).Styles.ElementAt(0), "font-weight", "bold"); }
public void IdentityToAllP() { string html = @"<style> #dv p { font-size:20px; } </style> <div id='dv'><div><p>one</p></div><span><p>two</p></span></div>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; while (node.Tag != "div") { node = node.Next; } TestUtility.AnalyzeNode(node, "div", "<div><p>one</p></div><span><p>two</p></span>", "<div id='dv'><div><p>one</p></div><span><p>two</p></span></div>", null, false, true, 2, 1, 0); TestUtility.CheckKeyValuePair(node.Attributes.ElementAt(0), "id", "dv"); TestUtility.AnalyzeNode(node.Children.ElementAt(0), "div", "<p>one</p>", "<div><p>one</p></div>", node, false, true, 1, 0, 0); TestUtility.AnalyzeNode(node.Children.ElementAt(0).Children.ElementAt(0), "p", "one", "<p>one</p>", node.Children.ElementAt(0), false, true, 1, 0, 1); TestUtility.CheckKeyValuePair(node.Children.ElementAt(0).Children.ElementAt(0).Styles.ElementAt(0), "font-size", "20px"); TestUtility.AnalyzeNode(node.Children.ElementAt(1), "span", "<p>two</p>", "<span><p>two</p></span>", node, false, true, 1, 0, 0); TestUtility.AnalyzeNode(node.Children.ElementAt(1).Children.ElementAt(0), "p", "two", "<p>two</p>", node.Children.ElementAt(1), false, true, 1, 0, 1); TestUtility.CheckKeyValuePair(node.Children.ElementAt(1).Children.ElementAt(0).Styles.ElementAt(0), "font-size", "20px"); }
public void DivAllNextP() { string html = @"<style> div~p { font-weight:bold; } </style> <div><p>1</p></div> test <p>one</p> <span>two</span> <p>three</p>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; bool divFound = false; bool spanFound = false; int pCount = 0; while (node != null) { if (node.Tag == "div") { divFound = true; TestUtility.AnalyzeNode(node, "div", "<p>1</p>", "<div><p>1</p></div>", null, false, true, 1, 0, 0); TestUtility.AnalyzeNode(node.Children.ElementAt(0), "p", "1", "<p>1</p>", node, false, true, 1, 0, 0); } if (node.Tag == "span") { spanFound = true; TestUtility.AnalyzeNode(node, "span", "two", "<span>two</span>", null, false, true, 1, 0, 0); } if (node.Tag == "p") { ++pCount; Assert.AreEqual(1, node.Styles.Count); TestUtility.CheckKeyValuePair(node.Styles.ElementAt(0), "font-weight", "bold"); } node = node.Next; } if (!divFound) { throw new Exception("div tag not found"); } if (!spanFound) { throw new Exception("span tag not found"); } if (pCount != 2) { throw new Exception("mismatch in p count"); } }
public void PNextDivSpan() { string html = @"<style> p + span { font-weight:bold; } </style> <p>one</p> <div>test</div> <span>two</span>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; bool pFound = false; bool divFound = false; bool spanFound = false; while (node != null) { if (node.Tag == "p") { pFound = true; TestUtility.AnalyzeNode(node, "p", "one", "<p>one</p>", null, false, true, 1, 0, 0); } if (node.Tag == "div") { divFound = true; TestUtility.AnalyzeNode(node, "div", "test", "<div>test</div>", null, false, true, 1, 0, 0); } if (node.Tag == "span") { spanFound = true; TestUtility.AnalyzeNode(node, "span", "two", "<span>two</span>", null, false, true, 1, 0, 0); } node = node.Next; } if (!pFound) { throw new Exception("p tag not found"); } if (!divFound) { throw new Exception("div tag not found"); } if (!spanFound) { throw new Exception("span tag not found"); } }
public void ElementIdentityStyles() { string path = TestUtility.GetFolderPath("Html\\elementidentity.htm"); string html = string.Empty; using (StreamReader sr = new StreamReader(path)) { html = sr.ReadToEnd(); } HtmlParser parser = new HtmlTextParser(html); parser.Parse(); parser.ParseStyles(); IHtmlNode node = parser.Current.Children.ElementAt(0); while (node.Tag != "body") { node = node.Next; } node = node.Children.ElementAt(0); while (node.Tag != "div") { node = node.Next; } node.AnalyzeNode("div", "test", "<div id=\"gray\">test</div>", node.Parent, false, true, 1, 1, 1); node.Styles.CheckKeyValuePair(0, "background-color", "#eee"); }
public void BackgroundColorSpecifity() { string path = TestUtility.GetFolderPath("Html\\backgroundcolorspecificity.htm"); string html = string.Empty; using (StreamReader sr = new StreamReader(path)) { html = sr.ReadToEnd(); } HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); IHtmlNode node = parser.Current; while (node.Tag != "html") node = node.Next; node = node.Children.ElementAt(0); while (node.Tag != "body") node = node.Next; node = node.Children.ElementAt(0); while (node.Tag != "ul") node = node.Next; node = node.Children.ElementAt(0); while (node.Tag != "li") node = node.Next; node = node.Children.ElementAt(0); while (node.Tag != "a") node = node.Next; Assert.AreEqual(1, node.Styles.Count); node.CheckStyle(0, "background-color", "red"); Assert.AreEqual(1, node.InheritedStyles.Count); node.CheckInheritedStyle(0, "background-color", "red"); }
public void MultipleCommentsInStyles() { string html = @"<style> .cls { /*color:red;*/ color:white; /*color:blue*/ } </style> <div class='cls'>test</div>"; HtmlParser parser = new HtmlTextParser(html); Assert.AreEqual(true, parser.Parse()); parser.ParseStyles(); IHtmlNode node = parser.Current; while (node.Tag != "div") node = node.Next; TestUtility.AnalyzeNode(node, "div", "test", "<div class='cls'>test</div>", null, false, true, 1, 1, 1); node.CheckStyle(0, "color", "white"); }
public void DivWithClassThenIdentity() { string html = @"<style> div.cls #dv { font-weight:bold; } </style> <div class='cls'><div id='dv'>two</div></div>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; while (node.Tag != "div") { node = node.Next; } TestUtility.AnalyzeNode(node, "div", "<div id='dv'>two</div>", "<div class='cls'><div id='dv'>two</div></div>", null, false, true, 1, 1, 0); TestUtility.CheckKeyValuePair(node.Attributes.ElementAt(0), "class", "cls"); TestUtility.AnalyzeNode(node.Children.ElementAt(0), "div", "two", "<div id='dv'>two</div>", node, false, true, 1, 1, 1); TestUtility.CheckKeyValuePair(node.Children.ElementAt(0).Attributes.ElementAt(0), "id", "dv"); TestUtility.CheckKeyValuePair(node.Children.ElementAt(0).Styles.ElementAt(0), "font-weight", "bold"); }
public void MultipleCommentsInStyleSheet() { string html = @"<style> /* .cls beginning */ .cls { color:white; } /* .cls end */ /* fnt beginning */ .fnt { font-weight:bold; } /* fnt end */ </style> <div class='cls fnt'>test</div>"; HtmlParser parser = new HtmlTextParser(html); Assert.AreEqual(true, parser.Parse()); parser.ParseStyles(); IHtmlNode node = parser.Current; while (node.Tag != "div") node = node.Next; TestUtility.AnalyzeNode(node, "div", "test", "<div class='cls fnt'>test</div>", null, false, true, 1, 1, 2); node.CheckStyle(0, "color", "white"); node.CheckStyle(1, "font-weight", "bold"); }
public void CheckMultipleClassesCSSOverride() { string html = @"<style> .ano { font-size:10px; } .cls { font-size:20px; } </style> <div class='cls ano'>one</div>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; while (node.Tag != "div") { node = node.Next; } TestUtility.AnalyzeNode(node, "div", "one", "<div class='cls ano'>one</div>", null, false, true, 1, 1, 1); TestUtility.CheckKeyValuePair(node.Attributes.ElementAt(0), "class", "cls ano"); TestUtility.CheckKeyValuePair(node.Styles.ElementAt(0), "font-size", "20px"); }
public void CascadeCSS() { string html = @"<style> .entry .updated { color: green; } .updated { color: red; } </style> <div class='entry'><span class='updated'>test</span></div>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; while (node.Tag != "div") node = node.Next; IHtmlNode div=node; node = node.Children.ElementAt(0); TestUtility.AnalyzeNode(node, "span", "test", "<span class='updated'>test</span>", div, false, true, 1, 1); Assert.AreEqual(1, node.Styles.Count); TestUtility.CheckKeyValuePair(node.Styles.ElementAt(0), "color", "green"); }