コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        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");
        }
コード例 #4
0
        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");
        }
コード例 #5
0
        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;");
        }
コード例 #6
0
        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>");
        }
コード例 #7
0
        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");
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: dantre/01-quality
 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.");
 }