private string CreateHtmlTree(ChmDocumentNode nodo, int nivel) { if (Project.MaxHeaderContentTree != 0 && nivel > Project.MaxHeaderContentTree) { return(""); } string texto = ""; if (!nodo.Href.Equals("")) { texto = "<li><a href=\"" + nodo.Href; texto += "\">" + nodo.HtmlEncodedTitle + "</a>"; } if (nodo.Children.Count > 0) { if (Project.MaxHeaderContentTree == 0 || nivel < Project.MaxHeaderContentTree) { texto += "\n<ul>\n"; foreach (ChmDocumentNode hijo in nodo.Children) { texto += CreateHtmlTree(hijo, nivel + 1) + "\n"; } texto += "</ul>"; } } if (!texto.Equals("")) { texto += "</li>"; } return(texto); }
/// <summary> /// Adds footer and / or header, if its needed. /// </summary> /// <param name="node">Node with the body to write</param> /// <param name="document">Owner of the node</param> /// <returns>If a footer or a header was specified, return a copy /// of the original body with the footer and / or header added. If none /// was specified, return the original body itself.</returns> private HtmlNode AddFooterAndHeader(ChmDocumentNode node, ChmDocument document) { HtmlNode body = node.SplittedPartBody; if (HeaderHtmlCode == "" && FooterHtmlCode == "") { return(body); } // Clone the body: HtmlNode clonedBody = body.CloneNode(true); try { // Make previous, next and home link replacements: string header, footer; MakeLinkReplacements(node, document, out header, out footer); // Add content headers and footers: if (HeaderHtmlCode != "") { clonedBody.PrependChild(HtmlNode.CreateNode("<div>" + header + "</div>")); } if (FooterHtmlCode != "") { clonedBody.AppendChild(HtmlNode.CreateNode("<div>" + footer + "</div>")); } } catch (Exception ex) { log(new Exception("Error adding headers / footers to node " + node, ex)); } return(clonedBody); }
/// <summary> /// Generate a java help table of contents xml file. /// </summary> /// <param name="writer">File where to store the TOC</param> /// <param name="currentNode">Node to process now</param> /// <param name="currentLevel">Current deep level of the node into the document tree</param> /// <param name="maxLevelTOC">Maximum deep level into the tree to generate the TOC.</param> private void GenerateJavaHelpTOC(StreamWriter writer, ChmDocumentNode currentNode, int currentLevel) { if (Project.MaxHeaderContentTree != 0 && currentLevel > Project.MaxHeaderContentTree) { return; } //if (currentNode.HeaderTag != null) //{ //writer.WriteLine(currentNode.JavaHelpTOCEntry); String entry = "<tocitem text=\"" + currentNode.HtmlEncodedTitle + "\" target=\"" + JavaHelpTarget(currentNode) + "\""; if (currentNode.Children.Count == 0) { entry += " />"; } else { entry += ">"; } writer.WriteLine(entry); //} foreach (ChmDocumentNode child in currentNode.Children) { GenerateJavaHelpTOC(writer, child, currentLevel + 1); } if (currentNode.HeaderTag != null && currentNode.Children.Count > 0) { writer.WriteLine("</tocitem>"); } }
/// <summary> /// Writes an HTML file, adding the footer, header, etc if needed to the body. /// </summary> /// <param name="body">"body" tag to write into the html file</param> /// <param name="filePath">Path where to write the HTML file</param> /// <param name="UI">User interface of the application</param> public void ProcessAndSavePage(ChmDocumentNode node, ChmDocument document, string filePath) { HtmlNode body = node.SplittedPartBody; if (body == null) { throw new Exception("The node " + node + " has no body"); } // Make a copy of the body and add the header and footer: HtmlNode clonedBody = AddFooterAndHeader(node, document); StreamWriter writer; // Determine the encoding to write the page: Encoding writeEncoding = OutputEncoding; if (writeEncoding == null) { writeEncoding = inputEncoding; } if (writeEncoding != null) { writer = new StreamWriter(filePath, false, writeEncoding); } else { // Use the default encoding. writer = new StreamWriter(filePath, false); } writer.WriteLine(textBeforeBody.Replace(TITLETAG, "<title>" + node.Title + "</title>")); string bodyText = clonedBody.OuterHtml; // Seems to be a bug that puts "about:blank" on links. Remove them: bodyText = bodyText.Replace("about:blank", "").Replace("about:", ""); writer.WriteLine(bodyText); writer.WriteLine(textAfterBody); writer.Close(); // Clean the files using Tidy, only if it was written with UTF-8 if (AppSettings.UseTidyOverOutput && writeEncoding == Encoding.UTF8 && UseTidy) { TidyParser tidy = new TidyParser(ui, TidyParser.UTF8); tidy.DocType = TidyParser.LOOSE; tidy.Parse(filePath); } }
private string TOCEntry(ChmDocumentNode node) { string title = node.HtmlEncodedTitle; // Remove line breaks on title: They broke the attribute value and the CHM compiler // doest not recognize it title = title.Replace("\r\n", " ").Replace("\n", " "); string texto = "<LI> <OBJECT type=\"text/sitemap\">\n" + " <param name=\"Name\" value=\"" + title + "\">\n" + " <param name=\"Local\" value=\"" + node.Href; texto += "\">\n" + " </OBJECT>\n"; return(texto); }
private void GenerateTOCFile(StreamWriter writer, ChmDocumentNode nodo, int nivel) { if (Project.MaxHeaderContentTree != 0 && nivel > Project.MaxHeaderContentTree) { return; } writer.WriteLine(/*nodo.EntradaArbolContenidos*/ TOCEntry(nodo)); if (nodo.Children.Count > 0) { writer.WriteLine("<UL>"); foreach (ChmDocumentNode hijo in nodo.Children) { GenerateTOCFile(writer, hijo, nivel + 1); } writer.WriteLine("</UL>"); } }
private void GenerateHelpProject(List <string> additionalFilesRelativePaths) { // Get the name of the first splitted file: string firstTopicFile = string.Empty; //if (Document.RootNode.Children.Count > 0) // firstTopicFile = Document.RootNode.Children[0].DestinationFileName; ChmDocumentNode firstTopicNode = Document.FirstNodeWithContent; if (firstTopicNode != null && !string.IsNullOrEmpty(firstTopicNode.DestinationFileName)) { firstTopicFile = firstTopicNode.DestinationFileName; } string filePath = ChmProjectPath; StreamWriter writer = new StreamWriter(filePath, false, Encoding); writer.WriteLine("[OPTIONS]"); writer.WriteLine("Compatibility=1.1 or later"); writer.WriteLine("Compiled file=" + CHMFILENAME); writer.WriteLine("Contents file=" + TOCFILENAME); writer.WriteLine("Default topic=" + firstTopicFile); writer.WriteLine("Display compile progress=No"); writer.WriteLine("Full-text search=Yes"); writer.WriteLine("Index file=" + INDEXFILENAME); writer.WriteLine("Language=0x" + Convert.ToString(HelpWorkshopCulture.LCID, 16) + " " + HelpWorkshopCulture.DisplayName); writer.WriteLine("Title=" + Project.HelpTitle); writer.WriteLine("\r\n[FILES]"); foreach (string extraFile in additionalFilesRelativePaths) { writer.WriteLine(extraFile); } List <string> lista = Document.ListaArchivosGenerados(); foreach (string arc in lista) { writer.WriteLine(arc); } writer.WriteLine("\r\n[INFOTYPES]\r\n"); writer.Close(); }
/// <summary> /// Returns the header/footer page texts with navigation links replaced /// </summary> /// <param name="node">Current page to calculate the navigation links</param> /// <param name="document">Owner of the page</param> /// <param name="headerHtmlCode">The header with links replaced</param> /// <param name="footerHtmlCode">The footer with links replaced</param> private void MakeLinkReplacements(ChmDocumentNode node, ChmDocument document, out string headerHtmlCode, out string footerHtmlCode) { string previousLink, nextLink, homeLink; previousLink = nextLink = homeLink = "#"; // Home: if (document.PagesIndex.Count > 0) { homeLink = document.PagesIndex[0]; } int currentPageIdx = document.PagesIndex.IndexOf(node.DestinationFileName); if (currentPageIdx >= 0) { // Previous if (currentPageIdx > 0) { previousLink = document.PagesIndex[currentPageIdx - 1]; } // Next if (currentPageIdx < (document.PagesIndex.Count - 1)) { nextLink = document.PagesIndex[currentPageIdx + 1]; } } // Make replacements: headerHtmlCode = HeaderHtmlCode.Replace(PREVIOUSPAGELINK, previousLink) .Replace(NEXTPAGELINK, nextLink) .Replace(HOMEPAGELINK, homeLink); footerHtmlCode = FooterHtmlCode.Replace(PREVIOUSPAGELINK, previousLink) .Replace(NEXTPAGELINK, nextLink) .Replace(HOMEPAGELINK, homeLink); }
/// <summary> /// Tag for a java help map file of this section. /// </summary> public string JavaHelpMapEntry(ChmDocumentNode node) { return("<mapID target=\"" + JavaHelpTarget(node) + "\" url=\"" + node.Href + "\" />"); }
/// <summary> /// Tag for a java help index file of this section. /// </summary> private string JavaHelpIndexEntry(ChmDocumentNode node) { return("<indexitem text=\"" + node.HtmlEncodedTitle + "\" target=\"" + JavaHelpTarget(node) + "\" />"); }
private string JavaHelpTarget(ChmDocumentNode node) { return(node.HtmlEncodedTitle); }