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 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 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 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 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 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 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 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 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 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 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 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 CustomAttributeWithValueOnly() { string html = @"<style> [attr='val'] { font-weight:bold; } </style> <div attr='val'>one</div> <div 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", "one", "<div attr='val'>one</div>", null, false, true, 1, 1, 1); TestUtility.CheckKeyValuePair(node.Attributes.ElementAt(0), "attr", "val"); TestUtility.CheckKeyValuePair(node.Styles.ElementAt(0), "font-weight", "bold"); node = node.Next; while (node.Tag != "div") { node = node.Next; } TestUtility.AnalyzeNode(node, "div", "", "<div attr></div>", null, false, false, 0, 1, 0); TestUtility.CheckKeyValuePair(node.Attributes.ElementAt(0), "attr", ""); Assert.IsNull(node.Next); }
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 DivGlobalStyle() { string html = @"<style> div * { background-color:red; } </style> <div><p>one</p><hr/></div> <p>three</p> <span>four</span>"; 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>one</p><hr/>", "<div><p>one</p><hr/></div>", null, false, true, 2, 0, 0); TestUtility.AnalyzeNode(node.Children.ElementAt(0), "p", "one", "<p>one</p>", node, false, true, 1, 0, 1); TestUtility.CheckKeyValuePair(node.Children.ElementAt(0).Styles.ElementAt(0), "background-color", "red"); TestUtility.AnalyzeNode(node.Children.ElementAt(1), "hr", "<hr/>", "<hr/>", node, true, false, 0, 0, 1); TestUtility.CheckKeyValuePair(node.Children.ElementAt(1).Styles.ElementAt(0), "background-color", "red"); while (node.Tag != "p") { node = node.Next; } TestUtility.AnalyzeNode(node, "p", "three", "<p>three</p>", null, false, true, 1, 0, 0); while (node.Tag != "span") { node = node.Next; } TestUtility.AnalyzeNode(node, "span", "four", "<span>four</span>", null, false, true, 1, 0, 0); }
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 IdentityLastChildP() { string html = @"<style> #dv:last-child p { background-color:red; } </style> <body><div id='dv'><div><p>three</p><span>two</span></div></div></body>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; while (node.Tag != "body") { node = node.Next; } IHtmlNode body = node; node = node.Children.ElementAt(0); while (node.Tag != "div") { node = node.Next; } TestUtility.AnalyzeNode(node, "div", "<div><p>three</p><span>two</span></div>", "<div id='dv'><div><p>three</p><span>two</span></div></div>", body, false, true, 1, 1, 0); TestUtility.CheckKeyValuePair(node.Attributes.ElementAt(0), "id", "dv"); IHtmlNode parent = node; node = node.Children.ElementAt(0); TestUtility.AnalyzeNode(node, "div", "<p>three</p><span>two</span>", "<div><p>three</p><span>two</span></div>", parent, false, true, 2, 0, 0); TestUtility.AnalyzeNode(node.Children.ElementAt(0), "p", "three", "<p>three</p>", node, false, true, 1, 0, 1); TestUtility.CheckKeyValuePair(node.Children.ElementAt(0).Styles.ElementAt(0), "background-color", "red"); TestUtility.AnalyzeNode(node.Children.ElementAt(1), "span", "two", "<span>two</span>", node, false, true, 1, 0, 0); }
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"); }
public void PDivWithImmediateChildrenSpan() { string html = @"<style> div > span, p { background-color:red; } </style> <p>1</p><div><span>2</span></div><span>3</span>"; HtmlParser parser = new HtmlTextParser(html); Assert.IsTrue(parser.Parse()); parser.ParseStyles(); Assert.IsNotNull(parser.Current); IHtmlNode node = parser.Current; while (node.Tag != "p") { node = node.Next; } node.AnalyzeNode("p", "1", "<p>1</p>", null, false, true, 1, 0, 1); node.Styles.CheckKeyValuePair(0, "background-color", "red"); node = node.Next; node.AnalyzeNode("div", "<span>2</span>", "<div><span>2</span></div>", null, false, true, 1, 0, 0); node.Children.ElementAt(0).AnalyzeNode("span", "2", "<span>2</span>", node, false, true, 1, 0, 1); node.Children.ElementAt(0).Styles.CheckKeyValuePair(0, "background-color", "red"); node = node.Next; node.AnalyzeNode("span", "3", "<span>3</span>", null, false, true, 1, 0, 0); }
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 StylesFromDivAndSpan() { string html = @"<style> span { font-family: arial; } div > span { font-size:15pt; } </style> <div><span>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; } node.AnalyzeNode("div", "<span>test</span>", "<div><span>test</span></div>", null, false, true, 1, 0, 0); node.Children.ElementAt(0).AnalyzeNode("span", "test", "<span>test</span>", node, false, true, 1, 0, 2); node.Children.ElementAt(0).Styles.CheckKeyValuePair(0, "font-size", "15pt"); node.Children.ElementAt(0).Styles.CheckKeyValuePair(1, "font-family", "arial"); }
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 StylesFromInlineDivClassAndSpanInlineClass() { string html = @"<style> span { font-family: arial !important; } div > span { font-size:15pt; } .d > span { font-weight:normal !important; } .s { font-weight:bold; } </style> <div class='d'><span style='font-family:verdana' class='s'>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; } node.AnalyzeNode("div", "<span style='font-family:verdana' class='s'>test</span>", "<div class='d'><span style='font-family:verdana' class='s'>test</span></div>", null, false, true, 1, 1, 0); node.Attributes.CheckKeyValuePair(0, "class", "d"); node.Children.ElementAt(0).AnalyzeNode("span", "test", "<span style='font-family:verdana' class='s'>test</span>", node, false, true, 1, 2, 3); node.Children.ElementAt(0).Attributes.CheckKeyValuePair(0, "style", "font-family:verdana"); node.Children.ElementAt(0).Attributes.CheckKeyValuePair(1, "class", "s"); node.Children.ElementAt(0).Styles.CheckKeyValuePair(0, "font-size", "15pt"); node.Children.ElementAt(0).Styles.CheckKeyValuePair(1, "font-weight", "normal"); node.Children.ElementAt(0).Styles.CheckKeyValuePair(2, "font-family", "arial"); }
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 GlobalAndElementSelector() { string path = TestUtility.GetFolderPath("Html\\globalselectors.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; Assert.IsNotNull(node); Assert.AreEqual(true, node.HasChildren); node = node.Children.ElementAt(0); while (node.Tag != "body") { node = node.Next; } IHtmlNode body = node; node = node.Children.ElementAt(0); while (node.Tag != "div") { node = node.Next; } TestUtility.AnalyzeNode(node, "div", "div", "<div>div</div>", body, false, true, 1, 0, 1); node.CheckStyle(0, "color", "red"); while (node.Tag != "p") { node = node.Next; } TestUtility.AnalyzeNode(node, "p", "p", "<p>p</p>", body, false, true, 1, 0, 1); node.CheckStyle(0, "color", "blue"); while (node.Tag != "span") { node = node.Next; } TestUtility.AnalyzeNode(node, "span", "span", "<span>span</span>", body, false, true, 1, 0, 1); node.CheckStyle(0, "color", "red"); }