Beispiel #1
0
        public static void RunTestJS(string input, bool SafeMode, bool ExtraMode, bool MarkdownInHtml, bool AutoHeadingIDs)
        {
            string normalized_input = input.Replace("\r\n", "\n").Replace("\r", "\n");

            // Work out the expected output using C# implementation
            var md = new Markdown();
            md.SafeMode = SafeMode;
            md.ExtraMode = ExtraMode;
            md.MarkdownInHtml = MarkdownInHtml;
            md.AutoHeadingIDs = AutoHeadingIDs;
            string expected = md.Transform(normalized_input);

            // Transform using javascript implementation
            string actual = TransformUsingJS(input, SafeMode, ExtraMode, MarkdownInHtml, AutoHeadingIDs);

            actual = actual.Replace("\r", "");
            expected = expected.Replace("\r", "");

            string sep = new string('-', 30) + "\n";

            Console.WriteLine("Input:\n" + sep + input);
            Console.WriteLine("Actual:\n" + sep + actual);
            Console.WriteLine("Expected:\n" + sep + expected);

            // Check it
            Assert.AreEqual(expected, actual);
        }
Beispiel #2
0
        /// <summary>
        /// performs a rough benchmark of the Markdown engine using small, medium, and large input samples 
        /// please DO NOT MODIFY the input samples or the benchmark itself as this will invalidate previous 
        /// benchmark runs!
        /// </summary>
        static void Benchmark(string text, int iterations)
        {
            var m = new Markdown();

            var sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < iterations; i++)
                m.Transform(text);
            sw.Stop();

            Console.WriteLine("input string length: " + text.Length);
            Console.Write(iterations + " iteration" + (iterations == 1 ? "" : "s") + " in " + sw.ElapsedMilliseconds + " ms");
            if (iterations == 1)
                Console.WriteLine();
            else
                Console.WriteLine(" (" + Convert.ToDouble(sw.ElapsedMilliseconds) / Convert.ToDouble(iterations) + " ms per iteration)");
        }
Beispiel #3
0
        public static void RunResourceTest(string resourceName)
        {
            string input = Utils.LoadTextResource(resourceName);
            string expected = Utils.LoadTextResource(System.IO.Path.ChangeExtension(resourceName, "html"));

            var md = new Markdown();
            md.SafeMode = resourceName.IndexOf("(SafeMode)") >= 0;;
            md.ExtraMode = resourceName.IndexOf("(ExtraMode)") >= 0;;
            md.MarkdownInHtml = resourceName.IndexOf("(MarkdownInHtml)") >= 0;
            md.AutoHeadingIDs = resourceName.IndexOf("(AutoHeadingIDs)") >= 0;

            string actual = md.Transform(input);
            string actual_clean = Utils.strip_redundant_whitespace(actual);
            string expected_clean = Utils.strip_redundant_whitespace(expected);

            string sep = new string('-', 30) + "\n";

            Console.WriteLine("Input:\n" + sep + input);
            Console.WriteLine("Actual:\n" + sep + actual);
            Console.WriteLine("Expected:\n" + sep + expected);

            Assert.AreEqual(expected_clean, actual_clean);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Markdown m = new Markdown();
            m.SafeMode = false;
            m.ExtraMode = true;
            m.AutoHeadingIDs = true;
            //			m.SectionHeader = "<div class=\"header\">{0}</div>\n";
            //			m.SectionHeadingSuffix = "<div class=\"heading\">{0}</div>\n";
            //			m.SectionFooter = "<div class=\"footer\">{0}</div>\n\n";
            //			m.SectionHeader = "\n<div class=\"section_links\"><a href=\"/edit?section={0}\">Edit</a></div>\n";
            //			m.HtmlClassTitledImages = "figure";
            //			m.DocumentRoot = "C:\\users\\bradr\\desktop";
            //			m.DocumentLocation = "C:\\users\\bradr\\desktop\\100D5000";
            //			m.MaxImageWidth = 500;
            m.FormatCodeBlock = FormatCodePrettyPrint;
            m.ExtractHeadBlocks = true;
            m.UserBreaks = true;

            string markdown=FileContents("input.txt");
            string str = m.Transform(markdown);
            Console.Write(str);

            var sections = Markdown.SplitUserSections(markdown);
            for (int i = 0; i < sections.Count; i++)
            {
                Console.WriteLine("---- Section {0} ----", i);
                Console.Write(sections[i]);
                Console.Write("\n");
            }
            Console.WriteLine("------------------");

            Console.WriteLine("------Joined-------");
            Console.WriteLine(Markdown.JoinUserSections(sections));
            Console.WriteLine("------Joined-------");

            Console.WriteLine("------start head block-------");
            Console.WriteLine(m.HeadBlockContent);
            Console.WriteLine("------end head block-------");
        }