Esempio n. 1
0
        public void PackageLooseFilesWebUrlToZipTest()
        {
            var    packager = new HtmlPackager();
            string zipFile  = @"c:\temp\GeneratedHtml\HtmlOutput.zip";
            bool   result   = packager.PackageHtmlToZipFile("https://MarkdownMonster.west-wind.com/", zipFile);

            Assert.IsTrue(result, packager.ErrorMessage);

            ShellUtils.GoUrl(zipFile);
        }
        public void PackageLooseFilesWebUrlTest()
        {
            var    packager   = new HtmlPackager();
            string outputFile = @"c:\temp\GeneratedHtml\Output.html";
            bool   result     = packager.PackageHtmlToFolder("http://west-wind.com/", outputFile, null, true);

            Assert.IsTrue(result);

            ShellUtils.GoUrl(outputFile);
        }
        public void PackageLooseFilesLocalTest()
        {
            var    packager   = new HtmlPackager();
            string outputFile = @"c:\temp\GeneratedHtml\Output.html";
            bool   result     = packager.PackageHtmlToFolder(@"c:\temp\tmpFiles\_MarkdownMonster_Preview.html", outputFile,
                                                             null, true);

            Assert.IsTrue(result);

            ShellUtils.GoUrl(outputFile);
        }
        public void PackageFromWebTest()
        {
            var    packager = new HtmlPackager();
            string packaged = packager.PackageHtml("https://west-wind.com");

            string outputFile = InputFile.Replace(".html", "_PACKAGED.html");

            File.WriteAllText(outputFile, packaged);

            ShellUtils.GoUrl(outputFile);

            Console.WriteLine(packaged);

            Assert.IsNotNull(packaged);
        }
Esempio n. 5
0
        public void Package()
        {
            var    packager = new HtmlPackager();
            string packaged = packager.PackageLocalHtml(InputFile);

            string outputFile = InputFile.Replace(".html", "_PACKAGED.html");

            File.WriteAllText(outputFile, packaged);

            ShellUtils.GoUrl(outputFile);

            Console.WriteLine(packaged);

            Assert.IsNotNull(packaged);
        }
Esempio n. 6
0
        public void PackageFromFileTest()
        {
            var    packager = new HtmlPackager();
            string packaged = packager.PackageHtml(InputFile);

            string outputFile = InputFile.Replace(".html", "_PACKAGED.html");

            File.WriteAllText(outputFile, packaged);

            Console.WriteLine(packaged);

            Assert.IsNotNull(packaged);

#if !NETCORE
            ShellUtils.GoUrl(outputFile);
#endif
        }
Esempio n. 7
0
        void SaveAsHtml()
        {
            SaveAsHtmlCommand = new CommandBase((s, e) =>
            {
                var tab = Model.Window.TabControl?.SelectedItem as TabItem;
                var doc = tab?.Tag as MarkdownDocumentEditor;
                if (doc == null)
                {
                    return;
                }

                var folder = Path.GetDirectoryName(doc.MarkdownDocument.Filename);

                SaveFileDialog sd = new SaveFileDialog
                {
                    Filter =
                        "Self contained Html Page (Html with embedded dependencies)|*.html|" +
                        "Raw Html Fragment (generated Html only)|*.html",
                    FilterIndex      = 1,
                    InitialDirectory = folder,
                    FileName         = Path.ChangeExtension(doc.MarkdownDocument.Filename, "html"),
                    CheckFileExists  = false,
                    OverwritePrompt  = true,
                    CheckPathExists  = true,
                    RestoreDirectory = true,
                    Title            = "Save As Html"
                };

                bool?result = null;
                try
                {
                    result = sd.ShowDialog();
                }
                catch (Exception ex)
                {
                    mmApp.Log("Unable to save html file: " + doc.MarkdownDocument.Filename, ex);
                    MessageBox.Show(
                        $@"Unable to open file:\r\n\r\n" + ex.Message,
                        "An error occurred trying to open a file",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }

                if (result != null && result.Value)
                {
                    if (sd.FilterIndex == 2)
                    {
                        var html = doc.RenderMarkdown(doc.GetMarkdown(),
                                                      mmApp.Configuration.MarkdownOptions.RenderLinksAsExternal);

                        if (!doc.MarkdownDocument.WriteFile(sd.FileName, html))
                        {
                            MessageBox.Show(Model.Window,
                                            $"{sd.FileName}\r\n\r\nThis document can't be saved in this location. The file is either locked or you don't have permissions to save it. Please choose another location to save the file.",
                                            "Unable to save Document", MessageBoxButton.OK, MessageBoxImage.Warning);
                            SaveAsHtmlCommand.Execute(null);
                            return;
                        }

                        mmFileUtils.OpenFileInExplorer(sd.FileName);
                        Model.Window.ShowStatus("Raw HTML File created.", mmApp.Configuration.StatusMessageTimeout);
                    }
                    else
                    {
                        if (doc.MarkdownDocument.RenderHtmlToFile(usePragmaLines: false,
                                                                  renderLinksExternal: mmApp.Configuration.MarkdownOptions.RenderLinksAsExternal,
                                                                  filename: sd.FileName) == null)
                        {
                            MessageBox.Show(Model.Window,
                                            $"{sd.FileName}\r\n\r\nThis document can't be saved in this location. The file is either locked or you don't have permissions to save it. Please choose another location to save the file.",
                                            "Unable to save Document", MessageBoxButton.OK, MessageBoxImage.Warning);
                            SaveAsHtmlCommand.Execute(null);
                            return;
                        }

                        bool success = false;
                        try
                        {
                            Model.Window.ShowStatus("Packing HTML File. This can take a little while.",
                                                    mmApp.Configuration.StatusMessageTimeout, FontAwesomeIcon.CircleOutlineNotch,
                                                    color: Colors.Goldenrod, spin: true);

                            string packaged;
                            var packager = new HtmlPackager();
                            packaged     = packager.PackageLocalHtml(sd.FileName);

                            success = true;

                            File.WriteAllText(sd.FileName, packaged);

                            mmFileUtils.OpenFileInExplorer(sd.FileName);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(Model.Window, "Couldn't package HTML file:\r\n\r\n" + ex.Message,
                                            "Couldn't create HTML Package File");
                            return;
                        }
                        finally
                        {
                            Model.Window.ShowStatus();
                            Model.Window.ShowStatus("Packaged HTML File created.",
                                                    mmApp.Configuration.StatusMessageTimeout);
                        }
                    }
                }
            }, (s, e) =>
            {
                if (!Model.IsEditorActive)
                {
                    return(false);
                }
                if (Model.ActiveDocument.Filename == "untitled")
                {
                    return(true);
                }
                if (Model.ActiveEditor.EditorSyntax != "markdown")
                {
                    return(false);
                }

                return(true);
            });
        }