internal static void HtmlTree <T>(IList <T> treeItems, HtmlTree htmlTree) { if (treeItems == null || treeItems.Count <= 0) { throw new Exception("HtmlTree<T>()转换的数据对象DbModel为空。"); } Type dbModelType = typeof(T); PropertyInfo field_id = null; // Id Field PropertyInfo field_pid = null; // Pid Field PropertyInfo field_text = null; // Text Field Attribute[] dbModelAttribytes = Attribute.GetCustomAttributes(dbModelType); foreach (Attribute attribute in dbModelAttribytes) { if (attribute is HtmlTreeAttribute) { HtmlTreeAttribute treeAttribute = (HtmlTreeAttribute)attribute; field_id = dbModelType.GetProperty(treeAttribute.ID); field_pid = dbModelType.GetProperty(treeAttribute.PID); field_text = dbModelType.GetProperty(treeAttribute.TextField); break; } } if (field_id == null && field_pid == null && field_text == null) { throw new Exception("HtmlTree<T>()未指定对象" + dbModelType.ToString() + "的自定义属性[HtmlTree(\"Id\",\"Pid\",\"Text Field\")]属性。"); } int treeLevel = 1; BuildHtmlTree(treeItems, htmlTree, -1, ref treeLevel, field_id, field_pid, field_text); }
private static void BuildHtmlTree <T>(IList <T> treeNodes, HtmlTree htmlTree, object pid, ref int nodeLevel, params PropertyInfo[] dbModelAttributes) { IEnumerable <T> subNodes = treeNodes.Where(x => dbModelAttributes[1].GetValue(x).Equals(pid)); foreach (var subNode in subNodes) { object value_id = dbModelAttributes[0].GetValue(subNode); object value_pid = dbModelAttributes[1].GetValue(subNode); object value_text = dbModelAttributes[2].GetValue(subNode); AFlag html_a = new AFlag(); html_a.Text = value_text.ToString(); SpanFlag html_span = new SpanFlag(); html_span.ClassName = "caret"; html_span.MenuLevel = nodeLevel; LiFlag html_li = new LiFlag(); html_li.Span = html_span; html_li.A = html_a; BuildHtmlTree(treeNodes, html_li.UL, value_id, ref nodeLevel, dbModelAttributes); nodeLevel++; htmlTree.LiNodes.Add(html_li); } }
public FrmRegularGuide(string pOriHtml, HtmlTree pTree, PlotWaterLine pPlotLine) { InitializeComponent(); mWaterLine = pPlotLine; mTree = pTree; mHtml = pOriHtml; }
public void CorrectColumnsUsageWithRowClassOnTheParentParent() { BootstrapColumnsValidator validator = new BootstrapColumnsValidator(); var source = @"<div class='row'> <div> <div class='col-md-8'> <b>Title 1</b> </div> <div class='col-md-4'> <b>Title 2</b> </div> </div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0].Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
private void URLButton_Click(object sender, RoutedEventArgs e) { if (original_url == URLText.Text) { HTMLList.DataContext = new CustomCrawlerDataGridViewModel(GetLoadResults()); return; } try { original_url = URLText.Text; root_url = string.Join("/", URLText.Text.Split(new char[] { '/' }, 4), 0, 3); if (driverCheck.IsChecked == false) { var html = NetCommon.DownloadString(URLText.Text); tree = new HtmlTree(html); tree.BuildTree(); HTMLList.DataContext = new CustomCrawlerDataGridViewModel(GetLoadResults()); } else { var driver = new SeleniumWrapper(); driver.Navigate(URLText.Text); tree = new HtmlTree(driver.GetHtml()); tree.BuildTree(); driver.Close(); HTMLList.DataContext = new CustomCrawlerDataGridViewModel(GetLoadResults()); } } catch (Exception ex) { MessageBox.Show(ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
public State(HtmlTree H) { Html = H; Html.JSState = this; /*ScriptEngine apiscope = new ScriptEngine(); * * apiscope.ForceStrictMode = true; * * apiscope.ExecuteFile("api/Document.js");*/ Engine.Global["document"] = new DocumentObject(this, Html); Engine.SetGlobalFunction("log", new Func <string, int>((str) => { Console.WriteLine(str); return(0); })); Engine.SetGlobalFunction("test", new Action(() => { foreach (HtmlNode node in Html.Elements) { foreach (KeyValuePair <string, string> attr in node.TagAttributes) { if (attr.Key == "change") { node.TagBody = "Javascript touched me :("; } } } })); }
public void WarnIfParentsElementIsMissingRowClass() { BootstrapColumnsValidator validator = new BootstrapColumnsValidator(); var source = @"<html> <body> <div class='someClass'> <div class='col-md-8'> <b>Title 1</b> </div> <div class='col-md-4'> <b>Title 2</b> </div> </div> </body> </html>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0].Children[0].Children[0]); int expected = 1; Assert.AreEqual(expected, compiled.Count); Assert.IsTrue(compiled[0].Message.Contains("col-md-8")); }
public void SentitiveFragmentCollection_IsDestructiveChange_Delete() { string html = "<!-- --> "; bool result; HtmlTree tree = ParseHtml(html); var cc = tree.CommentCollection; result = cc.IsDestructiveChange(0, 1, 0, new TextStream(html), new TextStream("!-- --> ")); Assert.True(result); result = cc.IsDestructiveChange(1, 1, 0, new TextStream(html), new TextStream("<-- --> ")); Assert.True(result); result = cc.IsDestructiveChange(4, 1, 0, new TextStream(html), new TextStream("<!-- --> ")); Assert.True(result); result = cc.IsDestructiveChange(5, 1, 0, new TextStream(html), new TextStream("<!-- --> ")); Assert.False(result); result = cc.IsDestructiveChange(7, 1, 0, new TextStream(html), new TextStream("<!-- -> ")); Assert.True(result); result = cc.IsDestructiveChange(10, 1, 0, new TextStream(html), new TextStream("<!-- -->")); Assert.False(result); }
private MarkdownPage ParsePage(string fileName) { string html = CommonMark.CommonMarkConverter.Convert(File.ReadAllText(fileName)); HtmlTree tree = new HtmlTree(new TextStream(html)); tree.Build(); ElementNode firstChild = tree.RootNode.Children[0]; ElementNode prop = firstChild.Children[0]; MarkdownPage page = new MarkdownPage(); page.Title = AttrValue(prop, "pageTitle", Path.GetFileNameWithoutExtension(fileName)); page.Description = AttrValue(prop, "description", page.Title); page.Content = html.Substring(firstChild.End, tree.RootNode.Length - firstChild.End).Trim(); page.Keywords = AttrValue(prop, "keywords", page.Title); page.Slug = AttrValue(prop, "slug", page.Title.ToLowerInvariant()); page.DateModified = File.GetLastWriteTime(fileName); page.FileName = fileName.Replace(BaseDirectory, string.Empty).Replace("\\", "/"); page.ShowInMenu = Path.GetFileName(fileName).StartsWith("_") ? false : true; if (prop.GetAttribute("order") != null) { page.Order = int.Parse(prop.GetAttribute("order").Value); } else { page.Order = 1000 + page.Title[0]; } return(page); }
public void CorrectColumnsUsageWithRowClassOnTheParentParent() { BootstrapColumnsValidator validator = new BootstrapColumnsValidator(); var source = @"<div class='row'> <div> <div class='col-md-8'> <b>Title 1</b> </div> <div class='col-md-4'> <b>Title 2</b> </div> </div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0].Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void ErrorMsgIfMoreThanTwelveColumns() { BootstrapColumnsValidator validator = new BootstrapColumnsValidator(); var source = @"<div class='row'> <div class='col-md-10'> <b>Title 1</b> </div> <div class='col-md-3'> <b>Title 2</b> </div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 1; Assert.AreEqual(expected, compiled.Count); Assert.IsTrue(compiled[0].Message.Contains("must not exceed 12")); Assert.IsTrue(compiled[0].Message.Contains("col-md-*")); }
private HtmlTree ParseHtml(string html) { HtmlParser parser = new HtmlParser(); HtmlTree tree = new HtmlTree(new TextStream(html)); tree.Build(); return(tree); }
public void CastReturnsTheSameNodeTyped() { HtmlElement htmlElement; var tree = HtmlTree.Create(DocumentFragment(htmlElement = Element("div"))); var treeElement = tree.FirstChild.Value.Cast <HtmlElement>(); Assert.Same(htmlElement, treeElement.Node); Assert.Same(tree.Node, treeElement.Parent.Value.Node); }
public void AsBaseNodeReturnsTheSameNode() { var tree = HtmlTree.Create(DocumentFragment(Element("div"))); var div = tree.FirstChild.Value; var baseNode = div.AsBaseNode(); Assert.Same(div.Node, baseNode.Node); Assert.Same(tree.Node, baseNode.Parent.Value.Node); }
public void ElementNode_GetPositionNodeTest() { string html = " <html dir=\"rtl\">foo</html>"; HtmlTree tree = ParseHtml(html); ElementNode element; AttributeNode attribute; var position = tree.RootNode.GetPositionElement(0, out element, out attribute); Assert.NotNull(element); Assert.True(element is RootNode); Assert.Null(attribute); Assert.Equal(HtmlPositionType.InContent, position); position = tree.RootNode.GetPositionElement(2, out element, out attribute); Assert.NotNull(element); Assert.Null(attribute); Assert.Equal(HtmlPositionType.ElementName, position); Assert.True(String.Compare(element.Name, "html") == 0); position = tree.RootNode.GetPositionElement(6, out element, out attribute); Assert.True(element is ElementNode); Assert.Equal(HtmlPositionType.ElementName, position); position = tree.RootNode.GetPositionElement(7, out element, out attribute); Assert.NotNull(element); Assert.NotNull(attribute); Assert.Equal(HtmlPositionType.InStartTag | HtmlPositionType.AttributeName, position); Assert.True(String.Compare(attribute.Name, "dir") == 0); position = tree.RootNode.GetPositionElement(11, out element, out attribute); Assert.NotNull(element); Assert.NotNull(attribute); Assert.Equal(HtmlPositionType.InStartTag | HtmlPositionType.AfterEqualsSign, position); Assert.True(String.Compare(attribute.Name, "dir") == 0); position = tree.RootNode.GetPositionElement(13, out element, out attribute); Assert.NotNull(element); Assert.NotNull(attribute); Assert.Equal(HtmlPositionType.InStartTag | HtmlPositionType.AttributeValue, position); position = tree.RootNode.GetPositionElement(19, out element, out attribute); Assert.NotNull(element); Assert.Null(attribute); Assert.Equal(HtmlPositionType.InContent, position); position = tree.RootNode.GetPositionElement(24, out element, out attribute); Assert.NotNull(element); Assert.Null(attribute); Assert.Equal(HtmlPositionType.InEndTag, position); }
public void ElementNode_GetCommonAncestorTest() { string html = "<head><style></style></head><body><table><tr><td><ul><li><td><a></a></td></tr><tr></tr></table></body>"; HtmlTree tree = ParseHtml(html); ElementNode head = tree.RootNode.Children[0]; ElementNode body = tree.RootNode.Children[1]; ElementNode style = head.Children[0]; ElementNode table = body.Children[0]; ElementNode tr1 = table.Children[0]; ElementNode tr2 = table.Children[1]; ElementNode td11 = tr1.Children[0]; ElementNode td12 = tr1.Children[1]; ElementNode ul = td11.Children[0]; ElementNode li = ul.Children[0]; ElementNode a = td12.Children[0]; var node = tree.RootNode.GetCommonAncestor(head, body); Assert.True(node is RootNode); node = tree.RootNode.GetCommonAncestor(td11, td12); Assert.Equal("tr", node.Name); node = tree.RootNode.GetCommonAncestor(tr1, tr2); Assert.Equal("table", node.Name); node = tree.RootNode.GetCommonAncestor(tr1, a); Assert.Equal("tr", node.Name); node = tree.RootNode.GetCommonAncestor(table, a); Assert.Equal("table", node.Name); node = tree.RootNode.GetCommonAncestor(ul, a); Assert.Equal("tr", node.Name); node = tree.RootNode.GetCommonAncestor(head, a); Assert.True(node is RootNode); node = tree.RootNode.GetCommonAncestor(ul, body); Assert.Equal("body", node.Name); node = tree.RootNode.GetCommonAncestor(li, style); Assert.True(node is RootNode); node = tree.RootNode.GetCommonAncestor(ul, li); Assert.Equal("ul", node.Name); }
public static void VerifyTree(EditorTree editorTree) { #if ___DEBUG if (editorTree.TextBuffer != null) { var fullParseTree = new HtmlTree(new TextProvider(editorTree.TextSnapshot)); fullParseTree.Build(rebuildCollection); CompareTrees(editorTree, fullParseTree); } #endif }
internal IReadOnlyList <INamedItemInfo> LoadFunctionInfoFromPackageHelpIndex() { List <INamedItemInfo> functions = new List <INamedItemInfo>(); string content = null; try { string htmlFile = Path.Combine(this.InstallPath, this.Name, "html", "00index.html"); if (File.Exists(htmlFile)) { using (StreamReader sr = new StreamReader(htmlFile, Encoding.UTF8)) { content = sr.ReadToEnd(); } } } catch (IOException) { } if (!string.IsNullOrEmpty(content)) { HtmlTree tree = new HtmlTree(new TextStream(content)); tree.Build(); FunctionSearch functionSearch = new FunctionSearch(functions); tree.Accept(functionSearch, null); } Dictionary <string, INamedItemInfo> functionIndex = new Dictionary <string, INamedItemInfo>(); foreach (INamedItemInfo ni in functions) { functionIndex[ni.Name] = ni; } IReadOnlyDictionary <string, string> mappedNames = GetMappedNames(); foreach (string mappedName in mappedNames.Keys) { INamedItemInfo ni; string actualName = mappedNames[mappedName]; if (functionIndex.TryGetValue(actualName, out ni)) { INamedItemInfo niAlias = new NamedItemInfo() { Name = mappedName, Description = ni.Description, ItemType = ni.ItemType }; functions.Add(niAlias); } } return(functions); }
public void SentitiveFragmentCollection_IsDestructiveChange_Multiple() { string html = "<!-- --><!-- "; bool result; HtmlTree tree = ParseHtml(html); var cc = tree.CommentCollection; result = cc.IsDestructiveChange(5, 4, 1, new TextStream(html), new TextStream("<!-- a!-- ")); Assert.True(result); result = cc.IsDestructiveChange(0, html.Length, 0, new TextStream(html), new TextStream(String.Empty)); Assert.True(result); }
private void VerifyPositions(string html, HtmlPositionType[] positionTypes) { var tree = new HtmlTree(new TextStream(html), null, null, ParsingMode.Html); tree.Build(); for (int i = 0; i < html.Length; i++) { ElementNode element; AttributeNode attribute; var pos = tree.RootNode.GetPositionElement(i, out element, out attribute); Assert.Equal(positionTypes[i], pos); } }
public void HtmlTree_VisitorTest() { string html = "<html><head>" + "<script>alert(\"boo!\")</script>" + "<style>.a { color: red; }</style>" + "</head>" + "<body style=\"text:green\" onload=\"some_script\">" + "</body></html>"; HtmlTree tree = ParseHtml(html); var visitor = new TestVisitor(); tree.RootNode.Accept(visitor, parameter: null); Assert.Equal(6, visitor.Count); // 5 + root node }
public void FoundationClassValidatorDoNothingIfClassAttributContainsNothingAboutColumns() { FoundationClassValidator validator = new FoundationClassValidator(); var source = @"<div class='somethingElse'>2 columns</div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void ValidColumnDeclaration() { FoundationClassValidator validator = new FoundationClassValidator(); var source = @"<div class='small-2 columns'>2 columns</div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public HtmlTreeBuilder(HtmlParser parser, HtmlTree tree) { Parser = parser; _tree = tree; parser.ParsingStarting += OnParseBegin; parser.ParsingComplete += OnParseEnd; parser.StartTagOpen += OnStartTagOpen; parser.StartTagClose += OnStartTagClose; parser.AttributeFound += OnAttribute; parser.EndTagOpen += OnEndTagOpen; parser.EndTagClose += OnEndTagClose; parser.CommentFound += OnComment; // For tree building purposes we don't care about comments or entities. // Colorable item collection cares so it should be listening to those events. }
public void ValidColumnDeclaration() { FoundationClassValidator validator = new FoundationClassValidator(); var source = @"<div class='small-2 columns'>2 columns</div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void NoWarningIfNoParentForColumns() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='medium-2 columns'>2 columns</div> <div class='medium-10 columns'>10 columns</div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void NoColumnsNoWarnings() { BootstrapColumnsValidator validator = new BootstrapColumnsValidator(); var source = @"<div class='someClass'> <i class='someOtherClass'></i> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void OkToHaveLessThan12ColumnsIfCenteredClassPresentEvenOnAnotherSize() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='row'> <div class='small-6 large-centered columns'>6 centered</div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void MinimalistCorrectColumnUsage() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='row'> <div class='columns'>12 columns</div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void MinimalistCorrectColumnUsage() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='row'> <div class='columns'>12 columns</div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void BootStrapClassValidatorDoNothingIfClassAttributIsMissing() { BootstrapClassValidator validator = new BootstrapClassValidator(); var source = @"<a id='someHyperlink' href='#'> Link text </a>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public HtmlView(MakerView top) { this.top = top; InitializeComponent(); TabText = "HTML"; htmlTree = new HtmlTree() { Dock = DockStyle.Fill }; this.DockStateChanged += new EventHandler(Reload); this.Controls.Add(htmlTree); top.InsertStripButton(-4, htmlTree.SelectorStripButton); top.InsertStripButton(-4, htmlTree.SelectorAreaStripButton); htmlTree.SelectedEventHandler += htmlTree_SelectedEventHandler; CloseButtonVisible = false; }
public void NoColumnsNoWarnings() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='someClass'> <i class='someOtherClass'></i> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void BootStrapClassValidatorDoNothingIfClassAttributIsMissing() { BootstrapClassValidator validator = new BootstrapClassValidator(); var source = @"<a id='someHyperlink' href='#'> Link text </a>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void CorrectComplexColumnsUsage() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='row'> <div class='small-8 medium-8 large-6 columns'>8-8-6</div> <div class='small-4 medium-4 large-6 columns'>4-4-6</div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void BootstrapNestedFontAwesomeTest() { BootstrapClassValidator validator = new BootstrapClassValidator(); var source = @"<span class='fa-stack fa-lg'> <i class='fa-circle fa-stack-2x fa'></i> <i class='fa fa-twitter fa-stack-1x fa-inverse'></i> </span>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void CorrectComplexColumnsUsage() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='row'> <div class='small-8 medium-8 large-6 columns'>8-8-6</div> <div class='small-4 medium-4 large-6 columns'>4-4-6</div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList <IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void BootstrapBtnPrimaryClassRequireBtnClassToo() { BootstrapClassValidator validator = new BootstrapClassValidator(); var source = @"<a class='btn-primary'> Link text </a>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]); int expected = 1; string expectedMessage = "When using \"btn-primary\", you must also specify the class \"btn\"."; Assert.AreEqual(expected, compiled.Count); Assert.AreEqual(expectedMessage, compiled[0].Message); }
public void InvalidComplexColumnsUsage_MissingOneLargeDefinition() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='row'> <div class='small-8 medium-8 large-10 columns'>8-8-6</div> <div class='small-4 medium-4 columns'>4-4-6</div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 1; Assert.AreEqual(expected, compiled.Count); Console.WriteLine(compiled[0].Message); }
public RootNode(HtmlTree owner) : base(null, 0, NameToken.Create(0, 0), owner.Text.Length) { _owner = owner; Children = ElementNode.EmptyCollection; }
public void NoWarningIfNoParentForColumns() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='medium-2 columns'>2 columns</div> <div class='medium-10 columns'>10 columns</div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void UnderTwelveIsOKIfEndClassIsThereAtLastColumn() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='row'> <div class='medium-3 columns'>3 columns</div> <div class='medium-3 columns'>3 columns</div> <div class='medium-3 columns end'>3 columns - End</div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void ErrorIfUnderTwelveWithoutEndClass() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='row'> <div class='medium-3 columns'>3 columns</div> <div class='medium-3 columns'>3 columns</div> <div class='medium-3 columns'>3 columns - End</div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 1; Assert.AreEqual(expected, compiled.Count); Assert.IsTrue(compiled[0].Message.Contains("the last column need the 'end' class element")); }
public void TotalOfGridColumnsMustEqual12ForAllTypeOfColumns() { BootstrapColumnsValidator validator = new BootstrapColumnsValidator(); var source = @"<div class='row'> <div class='col-md-8 col-sm-8'> <b>Title 1</b> </div> <div class='col-md-4 col-sm-6'> <b>Title 2</b> </div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 1; Assert.AreEqual(expected, compiled.Count); Assert.IsTrue(compiled[0].Message.Contains("must equal 12")); }
public void TwoRowsOnMobileDesign_InvalidExampleWithMoreThan12ColumnsBecauseNotMultipleOfTwelve() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='row'> <div class='small-6 large-2 columns'>...</div> <div class='small-6 large-8 columns'>...</div> <div class='small-8 large-2 columns'>...</div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 1; Assert.AreEqual(expected, compiled.Count); }
public void ErrorMsgIfMoreThanTwelveColumns() { BootstrapColumnsValidator validator = new BootstrapColumnsValidator(); var source = @"<div class='row'> <div class='col-md-10'> <b>Title 1</b> </div> <div class='col-md-3'> <b>Title 2</b> </div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 1; Assert.AreEqual(expected, compiled.Count); Assert.IsTrue(compiled[0].Message.Contains("must not exceed 12")); Assert.IsTrue(compiled[0].Message.Contains("col-md-*")); }
public void FoundationClassValidatorDoNothingIfClassAttributContainsNothingAboutColumns() { FoundationClassValidator validator = new FoundationClassValidator(); var source = @"<div class='somethingElse'>2 columns</div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void MissingColumnClass() { FoundationClassValidator validator = new FoundationClassValidator(); var source = @"<div class='small-2'>2 columns</div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0]); int expected = 1; string expectedMessagePart = "When using \"small-#\""; Assert.AreEqual(expected, compiled.Count); Assert.IsTrue(compiled[0].Message.Contains(expectedMessagePart)); System.Console.WriteLine(compiled[0].Message); }
public void TotalOfGridColumnsMustEqual12AndHandleOffSetCorrectly() { BootstrapColumnsValidator validator = new BootstrapColumnsValidator(); var source = @"<div class='row'> <div class='col-md-7'> <b>Title 1</b> </div> <div class='col-md-offset-1 col-md-4'> <b>Title 2</b> </div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void PullAndPushMustBeIgnored() { BootstrapColumnsValidator validator = new BootstrapColumnsValidator(); var source = @"<div class='row'> <div class='col-sm-6 col-md-9 col-md-push-3'> <b>Title 1</b> </div> <div class='col-md-3 col-md-pull-9 col-sm-6'> <b>Title 2</b> </div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void MustWorkForNonDivElementsToo() { BootstrapColumnsValidator validator = new BootstrapColumnsValidator(); var source = @"<div class='form-group row'> <label for='commentcontent' class='control-label col-sm-2'>Comment (no HTML allowed)</label> <div class='col-sm-10'> <textarea id='commentcontent' class='form-control' rows='4' placeholder='Comment' required></textarea> </div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
public void ErrorMsgIfMoreThanTwelveColumns() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='row'> <div class='medium-8 columns'>8 columns</div> <div class='medium-6 columns'>6 columns</div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 1; Assert.AreEqual(expected, compiled.Count); Assert.IsTrue(compiled[0].Message.Contains("more than 12 columns")); Assert.IsTrue(compiled[0].Message.Contains("medium-")); }
/// <summary> /// 数据提取 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TbarDrill_Click(object sender, EventArgs e) { if (TxtHtml.Text == "") { MessageBox.Show("请先请求数据"); } else { HtmlTree sTree = new HtmlTree(TxtHtml.Text, TxtAddress.Text, mPlotLine.CleanRule); if (sTree.LoadSuccess) { FrmRegularGuide mFrmRegularGuide = new FrmRegularGuide(TxtHtml.Text, sTree, mPlotLine); mFrmRegularGuide.ShowDialog(); } else { MessageBox.Show(sTree.Info); } } }
public void OkToHaveLessThan12ColumnsIfCenteredClassPresentEvenOnAnotherSize() { FoundationColumnsValidator validator = new FoundationColumnsValidator(); var source = @"<div class='row'> <div class='small-6 large-centered columns'>6 centered</div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 0; Assert.AreEqual(expected, compiled.Count); }
/// <summary> /// 执行特征筛选,并添加到缓冲区 /// </summary> public void Exe(Dictionary<string, string> pDic, HtmlTree pTree, HtmlNodeList pHtmlNodeList) { List<HtmlNode> sList = Path.Exe(pTree, pHtmlNodeList); if (sList != null) // { for (int i = 0; i < sList.Count; i++) { HtmlNode sHtmlNode = sList[i]; if (ResultMode == 0) // { #region 键值对模式 List<HtmlNodeList> sSubList = sHtmlNode.Nodes.Split(Spliter); for (int j = 0; j < sSubList.Count; j++) { HtmlNodeList sTextNodes = sSubList[j].GetTextNodes(false); if (sTextNodes.Count > 0) { for (int k = sTextNodes.Count - 1; k >= 0; k--) { if (sTextNodes[k].TextDecoded.Trim().Length == 0) { sTextNodes.RemoveAt(k); } } if (sTextNodes.Count > 0) { string[] sNameSpan = sTextNodes[0].TextDecoded.Trim().Replace(" ", "").Split(new char[] { ':', ':' }, StringSplitOptions.RemoveEmptyEntries); if (sNameSpan.Length > 0) { string sName = CommonService.ClearStr(sNameSpan[0]); StringBuilder Sb = new StringBuilder(); for (int k = 1; k < sNameSpan.Length; k++) { Sb.Append(sNameSpan[k]); } for (int k = 1; k < sTextNodes.Count; k++) { Sb.Append(sTextNodes[k].TextDecoded.Trim()); } if (FName != null && FName.Length > 0) { pDic[FName + "_" + sName] = Sb.ToString(); } else { pDic[sName] = Sb.ToString(); } } } } } #endregion } else if (ResultMode == 1) { string sValue = sHtmlNode.TextDecoded.Trim(); if (sValue.Length > 0) { pDic[FName] = sValue; } } } } }
public void WarnIfParentDivRowClassColumnIsMissing() { BootstrapColumnsValidator validator = new BootstrapColumnsValidator(); var source = @"<div class='someClass'> <div class='col-md-8'> <b>Title 1</b> </div> <div class='col-md-4'> <b>Title 2</b> </div> </div>"; var tree = new HtmlTree(new TextStream(source)); tree.Build(); IList<IHtmlValidationError> compiled = validator.ValidateElement(tree.RootNode.Children[0].Children[0]); int expected = 1; Assert.AreEqual(expected, compiled.Count); Assert.IsTrue(compiled[0].Message.Contains("col-md-8")); }