protected override bool CheckNode(HtmlNode node, string parameter) { var selectors = CssSelector.Parse(parameter); var nodes = new[] { node }; foreach (var selector in selectors) { if (selector.FilterCore(nodes).Count() == 1) { return(false); } } return(true); }
public static IList <HtmlAgilityPack.HtmlNode> QuerySelectorAll(this IEnumerable <HtmlAgilityPack.HtmlNode> nodes, string cssSelector) { if (cssSelector == null) { throw new ArgumentNullException("cssSelector"); } if (cssSelector.Contains(',')) { var combinedSelectors = cssSelector.Split(','); var rt = nodes.QuerySelectorAll(combinedSelectors[0]); foreach (var s in combinedSelectors.Skip(1)) { foreach (var n in nodes.QuerySelectorAll(s)) { if (!rt.Contains(n)) { rt.Add(n); } } } return(rt); } cssSelector = cssSelector.Trim(); var selectors = CssSelector.Parse(cssSelector); bool allowTraverse = true; foreach (var selector in selectors) { if (allowTraverse && selector.AllowTraverse) { nodes = Traverse(nodes); } nodes = selector.Filter(nodes); allowTraverse = selector.AllowTraverse; } return(nodes .Distinct() .ToList()); }
public void Multiselector() { var selector = CssSelector.Parse("h1, h2, h3"); var h1 = selector[0]; var h2 = selector[1]; var h3 = selector[2]; Assert.Equal("h1", h1[0].ToString()); Assert.Equal("h2", h2[0].ToString()); Assert.Equal("h3", h3[0].ToString()); Assert.Null(h1[0].Trailing); Assert.Null(h2[0].Trailing); Assert.Null(h3[0].Trailing); Assert.Equal("h1, h2, h3", selector.ToString()); }
public void C() { Assert.Equal("#networkLinks .block .edit:before", CssSelector.Parse("#networkLinks .block .edit:before").ToString()); }
public void A() { Assert.Equal("#a", CssSelector.Parse("#a").ToString()); Assert.Equal(".a", CssSelector.Parse(".a").ToString()); }
public void NthChildTests(string text) { var selector = CssSelector.Parse(text); Assert.Equal(text, selector.ToString()); }
public void Parse_should_roundtrip_nonstandard_names(string query) { var css = CssSelector.Parse(query); Assert.Equal(query, css.ToString()); }