/// <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> /// Constructor /// </summary> /// <param name="htmlDoc">The HTML document to parse</param> /// <param name="ui">Log generation object</param> /// <param name="project">Information about how to split the document</param> public ChmDocumentParser(HtmlDocument htmlDoc, UserInterface ui, ChmProject project) { // Create the empty document: Document = new ChmDocument(htmlDoc); UI = ui; Project = project; ReplaceBrokenLinks = AppSettings.ReplaceBrokenLinks; }
/// <summary> /// Saves the splitted content of this node into a file, if it has any. /// </summary> /// <param name="document">Owner of this node</param> /// <param name="directoryDstPath">Directory path where the content files will be stored</param> /// <param name="decorator">Tool to generate and decorate the HTML content files</param> /// <param name="indexer">Tool to index the saved content files. It can be null, if the content /// does not need to be indexed.</param> /// <returns>The content file name saved. Is this node has no content, it returns null</returns> public string SaveContent(ChmDocument document, string directoryDstPath, HtmlPageDecorator decorator, WebIndex indexer) { if (SplittedPartBody == null) { return(null); } // Save the section, adding header, footers, etc: string filePath = Path.Combine(directoryDstPath, DestinationFileName); decorator.ProcessAndSavePage(this, document, filePath); if (indexer != null) { // Store the document at the full text search index: indexer.AddPage(DestinationFileName, Title, SplittedPartBody); } return(DestinationFileName); }