static void Main(string[] args)
        {
            if (args.Length != 1 || args[0] == "/?")
            {
                ShowUsage();
                return;
            }

            try
            {
                var inputPath = args[0];
                var markupSource = File.ReadAllText(inputPath);

                var document = new DocumentProcessor(markupSource).Process();
                var htmlSource = new HtmlFormatter(document).FormatDocument();

                var outputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                    Path.GetFileNameWithoutExtension(inputPath) + ".html");
                File.WriteAllText(outputPath, htmlSource);

                Console.WriteLine($"[+] Converted from \"{inputPath}\" to \"{outputPath}\"");
            }
            catch (IOException e)
            {
                ShowError(e.Message);
            }
        }
        public void formatDocument_rendersWhitespaces()
        {
            var processor = new DocumentProcessor("yet another  test\nwith \t whitespaces");

            var document = processor.Process();
            var htmlSource = new HtmlFormatter(document).FormatDocument();

            CheckParagraphsPresence(htmlSource, "yet another test with whitespaces");
        }
        public void formatDocument_rendersText()
        {
            var processor = new DocumentProcessor("just a text");

            var document = processor.Process();
            var htmlSource = new HtmlFormatter(document).FormatDocument();

            CheckParagraphsPresence(htmlSource, "just a text");
        }
        public void formatDocument_rendersSeveralParagraphs()
        {
            var processor = new DocumentProcessor("\n\n\nthis text is\n\n divided to exactly two\n paragraphs");

            var document = processor.Process();
            var htmlSource = new HtmlFormatter(document).FormatDocument();

            CheckParagraphsPresence(htmlSource, "this text is", "divided to exactly two paragraphs");
        }
        public void formatDocument_avoidsXSS()
        {
            var processor = new DocumentProcessor("<b>XSS Test</b>");

            var document = processor.Process();
            var htmlSource = new HtmlFormatter(document).FormatDocument();

            CheckParagraphsPresence(htmlSource, "&lt;b&gt;XSS Test&lt;/b&gt;");
        }
        public void formatDocument_rendersNestedTags()
        {
            var processor = new DocumentProcessor("_ __ `emStrongCode` __ _");

            var document = processor.Process();
            var htmlSource = new HtmlFormatter(document).FormatDocument();

            CheckParagraphsPresence(htmlSource,
                "<em> <strong> <code>emStrongCode</code> </strong> </em>");
        }
        public void formatDocument_rendersDifferentTags()
        {
            var processor = new DocumentProcessor("_em_ __strong__ `code` word_with_digits_123");

            var document = processor.Process();
            var htmlSource = new HtmlFormatter(document).FormatDocument();

            CheckParagraphsPresence(htmlSource,
                "<em>em</em> <strong>strong</strong> <code>code</code> word_with_digits_123");
        }
Exemple #8
0
 static void Main(string[] args)
 {
     if (args.Length != 1)
     {
         Console.WriteLine("Usage: Markdown.exe [filename]");
         return;
     }
     if (File.Exists(args[0]))
     {
         var allText = File.ReadAllText(args[0]);
         var htmlFormatter = new HtmlFormatter();
         var processor = new MarkdownProcessor(allText, htmlFormatter);
         var html = processor.GetMarkdown();
         File.WriteAllText("result.html", html, Encoding.UTF8);
     }
     else
         Console.WriteLine("File not found.");
 }