Exemplo n.º 1
0
    private void Convert(string path)
    {
        ConverterOptions options = GetConverterOptions();

        if (path != null)
        {
            if (File.Exists(path))
            {
                MarkdownPath = path;
                _htmlPath    = null;

                Markdown = File.ReadAllText(path).Replace("\t", "  ");
                ConvertMarkdownAndFillTextFields(Markdown, path);

                if (_useContentScanner)
                {
                    print(ContentScanner.ParseScanrResults(ContentScanner.ScanMarkdown(Markdown)));
                }

                if (_saveOutputToHtml)
                {
                    _htmlPath = DragonUtil.GetFullPathWithoutExtension(path) + ".html";
                    Converter.ConvertMarkdownFileToHtmlFile(path, _htmlPath, options);
                }

                UIManager.Instance.HideLoadingScreen();
                UIManager.Instance.SetStatusText("Converted markdown! Copy HTML on right side or start Image Linker (experimental).");
            }
        }
        else
        {
            UIManager.Instance.HideLoadingScreen();
            UIManager.Instance.SetStatusText("No valid markdown chosen!");
        }
    }
Exemplo n.º 2
0
        public string ConvertToHtml(string markdownPath, string htmlPath, ConverterOptions options)
        {
            Console.WriteLine("Converting " + markdownPath + " to RW WordPress ready HTML...");

            if (htmlPath == null)
            {
                htmlPath = DragonUtil.GetFullPathWithoutExtension(markdownPath) + ".html";
            }

            if (DragonUtil.CheckFolderWritePermission(Path.GetDirectoryName(htmlPath)))
            {
                Converter.ConvertMarkdownFileToHtmlFile(markdownPath, htmlPath, options);
                Console.WriteLine("Saved HTML to custom location: " + htmlPath);
            }
            else
            {
                ColoredConsole.WriteLineWithColor("Conversion aborted, can't write to " + htmlPath, ConsoleColor.Red);
            }

            return(htmlPath);
        }
        public static void StartInteractive()
        {
            Console.WriteLine(" +-------------------------------------+");
            Console.WriteLine(" |                                     |");
            Console.WriteLine(" |          Interactive Wizard         |");
            Console.WriteLine(" |                                     |");
            Console.WriteLine(" +-------------------------------------+");

            string markdownPath = null;
            string htmlPath     = null;

            while (markdownPath == null)
            {
                Console.WriteLine("Please provide the path to the markdown file:");
                markdownPath = CoreConsoleShared.GetExistingFilePath();
            }

            string firstImageRight = null;

            while (firstImageRight != "y" && firstImageRight != "n")
            {
                Console.WriteLine(
                    "Should the first image be right aligned? This is useful for the 250x250 image at the top of tutorials. (y/n)");
                firstImageRight = Console.ReadLine();
            }

            string convertImagesWithAlt = null;

            while (convertImagesWithAlt != "y" && convertImagesWithAlt != "n")
            {
                Console.WriteLine(
                    "Should all images with an alt text be converted to captions? (y/n)");
                convertImagesWithAlt = Console.ReadLine();
            }

            string sameFolder = null;

            while (sameFolder != "y" && sameFolder != "n")
            {
                Console.WriteLine(
                    "Do you want to output the HTML file containing the WordPress ready code to the same folder as the markdown file? (y/n)");
                sameFolder = Console.ReadLine();
            }

            if (sameFolder == "y")
            {
                htmlPath = DragonUtil.GetFullPathWithoutExtension(markdownPath) + ".html";
            }
            else
            {
                while (htmlPath == null || htmlPath == markdownPath)
                {
                    if (htmlPath == markdownPath)
                    {
                        Console.WriteLine(
                            "Output file can't be the same as the input file! This WILL lead to data loss.");
                    }

                    Console.WriteLine("Please provide the location and name for the output html file:");
                    Console.WriteLine("(e.g. C:\\MyNewFile.html)");
                    htmlPath = CoreConsoleShared.GetNewFilePath();
                }
            }

            string uploadImages = null;

            while (uploadImages != "y" && uploadImages != "n" && uploadImages != "only html")
            {
                Console.WriteLine(
                    "Do you want to upload all images and update the links in both the markdown file and the generated html? (y/only html/n)");
                uploadImages = Console.ReadLine();
            }

            string ready = null;

            while (ready != "y" && ready != "n")
            {
                Console.WriteLine("Ready to start the conversion!");
                Console.WriteLine("");
                Console.WriteLine("Parameters:");
                Console.WriteLine("Markdown file path (input): " + markdownPath);
                Console.WriteLine("Generated HTML file path (output): " + htmlPath);
                Console.WriteLine("Upload images and update markdown and generated HTML file: " + uploadImages);
                Console.WriteLine("");
                Console.WriteLine("Are these parameters correct? (y/n)");
                ready = Console.ReadLine();
            }

            if (ready == "n")
            {
                Console.WriteLine("Conversion aborted.");
                return;
            }

            ConverterOptions options = new ConverterOptions
            {
                FirstImageIsAlignedRight = CoreConsoleShared.YesNoToBool(firstImageRight)
            };

            switch (uploadImages)
            {
            case "y":
                DoConversion(markdownPath, htmlPath, true, false, options);
                break;

            case "only html":
                DoConversion(markdownPath, htmlPath, true, true, options);
                break;

            case "n":
                DoConversion(markdownPath, htmlPath, false, false, options);
                break;
            }
        }