/// <summary> /// Tree section node constructor /// </summary> /// <param name="document">The document owner of this node</param> /// <param name="parent">Parent section of the section to create. null if the node to create is the root section.</param> /// <param name="node">HTML header tag for this section</param> /// <param name="ui">Application log. It can be null</param> public ChmDocumentNode(ChmDocument document, ChmDocumentNode parent, HtmlNode node, UserInterface ui) { this.Parent = parent; this.HeaderTag = node; Children = new List <ChmDocumentNode>(); HeaderLevel = HeaderTagLevel(node); DestinationFileName = ""; AnchorNames = new List <string>(); if (node != null) { // Check if the header tag has some anchor foreach (HtmlNode child in node.ChildNodes) { string name = ChmDocumentParser.GetAnchorName(child); if (name != null && name.Trim() != string.Empty) { AnchorNames.Add(name); } } if (AnchorNames.Count == 0) { // Si no tiene ningun nombre, darle uno artificial: int number = LatestCustomAnchorNumber++; string nodeName = "node" + number.ToString(); HtmlNode aTagElement = document.HtmlDoc.CreateElement("a"); // XHTML/HTML5 uses the "id" attribute, and HTML4 "name" // There is no safe way to check if its XHTML/HTML5 or a lower version, so put both: aTagElement.SetAttributeValue("name", nodeName); aTagElement.SetAttributeValue("id", nodeName); node.ChildNodes.Insert(0, aTagElement); AnchorNames.Add(nodeName); } } }
/// <summary> /// Builds the member listOfContainedANames, with all the A name tags contained into the body member. /// It does a recursive search for A tags. /// </summary> private void BuildListOfContainedANames(HtmlNode e) { string anchorName = ChmDocumentParser.GetAnchorName(e); if (anchorName != null) { DescendantAnchorNames.Add(anchorName); } // Do recursive search foreach (HtmlNode child in e.ChildNodes) { BuildListOfContainedANames(child); } }