Пример #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);
            }
        }
        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");
        }
        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);
        }