Пример #1
0
 public JavaHelpGenerator(string mainSourceFile, ChmDocument document, UserInterface ui,
                          ChmProject project, HtmlPageDecorator decorator)
     : base(document, ui, project, decorator)
 {
     JavaHelpDirectoryGeneration = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(mainSourceFile)) +
                                   "-javahelp";
 }
Пример #2
0
        /// <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);
        }
Пример #3
0
 protected ContentDirectoryGenerator(ChmDocument document, UserInterface ui,
                                     ChmProject project, HtmlPageDecorator decorator)
 {
     this.Document  = document;
     this.UI        = ui;
     this.Project   = project;
     this.Decorator = decorator;
 }
Пример #4
0
        public ChmGenerator(ChmDocument document, UserInterface ui, ChmProject project,
                            List <string> additionalFiles, HtmlPageDecorator decorator)
            : base(document, ui, project, decorator)
        {
            this.Document        = document;
            this.UI              = ui;
            this.Project         = project;
            this.AdditionalFiles = additionalFiles;

            // Get the encoding and culture for the chm:
            this.HelpWorkshopCulture = project.GetChmCulture(UI);
            this.Encoding            = ChmProject.GetChmEncoding(UI, this.HelpWorkshopCulture);
        }
Пример #5
0
        /// <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);
            }
        }
Пример #6
0
        /// <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);
        }
Пример #7
0
        public void GenerateHelp()
        {
            try
            {
                // Open and process source files
                OpenSourceFiles();

                if (UI.CancellRequested())
                {
                    return;
                }

                if (IsMSWord)
                {
                    // Añadir a la lista de archivos adicionales el directorio generado con
                    // los archivos del documento word:
                    string[] archivos = Directory.GetDirectories(MSWordHtmlDirectory);
                    foreach (string archivo in archivos)
                    {
                        AdditionalFiles.Add(archivo);
                    }
                }

                if (UI.CancellRequested())
                {
                    return;
                }

                // Build the tree structure of document titles.
                ChmDocumentParser parser = new ChmDocumentParser(HtmlDoc, this.UI, Project);
                Document = parser.ParseDocument();

                if (UI.CancellRequested())
                {
                    return;
                }

                if (Document.IsEmpty)
                {
                    // If the document is empty, we have finished
                    UI.Log("The document is empty. There is nothing to generate!", ChmLogLevel.ERROR);
                    return;
                }

                // Create decorators. This MUST to be called after the parsing: The parsing replaces the style tag
                // from the document
                PrepareHtmlDecorators();

                if (UI.CancellRequested())
                {
                    return;
                }

                GenerateChm();

                if (Project.GenerateWeb)
                {
                    GenerateWebSite();
                }

                if (UI.CancellRequested())
                {
                    return;
                }

                if (Project.GenerateJavaHelp)
                {
                    GenerateJavaHelp();
                }

                if (UI.CancellRequested())
                {
                    return;
                }

                if (Project.GeneratePdf)
                {
                    GeneratePdf();
                }

                if (UI.CancellRequested())
                {
                    return;
                }

                if (Project.GenerateXps)
                {
                    GenerateXps();
                }

                if (UI.CancellRequested())
                {
                    return;
                }

                // Execute command line:
                if (Project.CommandLine != null && !Project.CommandLine.Trim().Equals(""))
                {
                    ExecuteProjectCommandLine();
                }

                if (IsMSWord)
                {
                    // Era un doc word. Se creo un dir. temporal para guardar el html.
                    // Borrar este directorio:
                    Directory.Delete(MSWordHtmlDirectory, true);
                }
            }
            catch (Exception ex)
            {
                UI.Log("Error: " + ex.Message, ChmLogLevel.ERROR);
                UI.Log(ex);
                throw new Exception("General error: " + ex.Message, ex);;
            }
        }
Пример #8
0
 public WebHelpGenerator(ChmDocument document, UserInterface ui, ChmProject project,
                         HtmlPageDecorator decorator)
     : base(document, ui, project, decorator)
 {
 }