コード例 #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");
        }
        public void process_splitsByTwoNewLines_toNonEmptyParagraphs()
        {
            var processor = new DocumentProcessor(
                "\n\nfirstPar" +
                "\n\nmiddlePar line1\n line2" +
                "\n\n\nlastPar");

            var document = processor.Process();

            CollectionAssert.AreEqual(new []
            {
                new Paragraph(new List<IMarkupElement> { new Text("firstPar") }),
                new Paragraph(new List<IMarkupElement>
                {
                    new Text("middlePar"), new Whitespace(),
                    new Text("line1"), new Whitespace(), new Text("line2")
                }),
                new Paragraph(new List<IMarkupElement> { new Text("lastPar") }),
            }, document.Paragraphs);
        }