Beispiel #1
0
        public static void AssertNormalize(string input, string expected = null, bool trim = true, NormalizeOptions options = null, MarkdownPipeline pipeline = null)
        {
            expected = expected ?? input;
            input    = NormText(input, trim);
            expected = NormText(expected, trim);

            pipeline = pipeline ?? new MarkdownPipelineBuilder()
                       .UseAutoLinks()
                       .UseJiraLinks(new Extensions.JiraLinks.JiraLinkOptions("https://jira.example.com"))
                       .UseTaskLists()
                       .Build();

            var result = Markdown.Normalize(input, options, pipeline: pipeline);

            result = NormText(result, trim);

            TestParser.PrintAssertExpected(input, result, expected);
        }
Beispiel #2
0
        public void TestThematicInsideCodeBlockInsideList()
        {
            var input = @"1. In the :

   ```
   Id                                   DisplayName         Description
   --                                   -----------         -----------
   62375ab9-6b52-47ed-826b-58e47e0e304b Group.Unified       ...
   ```";

            TestParser.TestSpec(input, @"<ol>
<li><p>In the :</p>
<pre><code>Id                                   DisplayName         Description
--                                   -----------         -----------
62375ab9-6b52-47ed-826b-58e47e0e304b Group.Unified       ...
</code></pre></li>
</ol>");
        }
        private static void Check(string text, string expectedResult, string extensions = null)
        {
            var pipelineBuilder = new MarkdownPipelineBuilder().UsePreciseSourceLocation();

            if (extensions != null)
            {
                pipelineBuilder.Configure(extensions);
            }
            var pipeline = pipelineBuilder.Build();

            var document = Markdown.Parse(text, pipeline);

            var build = new StringBuilder();

            foreach (var val in document.Descendants())
            {
                var name = GetTypeName(val.GetType());
                build.Append($"{name,-12} ({val.Line,2},{val.Column,2}) {val.Span.Start,2}-{val.Span.End}\n");
                var attributes = val.TryGetAttributes();
                if (attributes != null)
                {
                    build.Append($"{"attributes",-12} ({attributes.Line,2},{attributes.Column,2}) {attributes.Span.Start,2}-{attributes.Span.End}\n");
                }
            }
            var result = build.ToString().Trim();

            expectedResult = expectedResult.Trim();
            expectedResult = expectedResult.Replace("\r\n", "\n").Replace("\r", "\n");

            if (expectedResult != result)
            {
                Console.WriteLine("```````````````````Source");
                Console.WriteLine(TestParser.DisplaySpaceAndTabs(text));
                Console.WriteLine("```````````````````Result");
                Console.WriteLine(result);
                Console.WriteLine("```````````````````Expected");
                Console.WriteLine(expectedResult);
                Console.WriteLine("```````````````````");
                Console.WriteLine();
            }

            TextAssert.AreEqual(expectedResult, result);
        }
Beispiel #4
0
        public void TestBugPipeTables()
        {
            // https://github.com/lunet-io/markdig/issues/73
            TestParser.TestSpec(@"| abc | def |
| --- | --- |
| 1 | ~3 |
", @"<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>~3</td>
</tr>
</tbody>
</table>", "advanced");
        }
Beispiel #5
0
        public void TestListBug()
        {
            // TODO: Add this test back to the CommonMark specs
            var text = @"- item1
  - item2
    - item3
      - item4";

            TestParser.TestSpec(text, @"<ul>
<li>item1
<ul>
<li>item2
<ul>
<li>item3
<ul>
<li>item4</li>
</ul></li>
</ul></li>
</ul></li>
</ul>
");
        }
Beispiel #6
0
        public void LinkTextMayContainBalancedBrackets(string linkText)
        {
            string markdown = $"[{linkText}](/uri)";
            string expected = $@"<p><a href=""/uri"">{linkText}</a></p>";

            TestParser.TestSpec(markdown, expected);

            // Make the link text unbalanced
            foreach (var bracketIndex in linkText
                     .Select((c, i) => new Tuple <char, int>(c, i))
                     .Where(t => t.Item1 == '[' || t.Item1 == ']')
                     .Select(t => t.Item2))
            {
                string brokenLinkText = linkText.Remove(bracketIndex, 1);

                markdown = $"[{brokenLinkText}](/uri)";
                expected = $@"<p><a href=""/uri"">{brokenLinkText}</a></p>";

                string actual = Markdown.ToHtml(markdown);
                Assert.AreNotEqual(expected, actual);
            }
        }
Beispiel #7
0
 public void TestBugWithEmphasisAndTable()
 {
     TestParser.TestSpec("**basics | 8:00**", "<p><strong>basics | 8:00</strong></p>", "advanced");
 }
Beispiel #8
0
        public void TestInvalidHtmlEntity()
        {
            var input = "9&ddr;&*&ddr;&de��__";

            TestParser.TestSpec(input, "<p>9&amp;ddr;&amp;*&amp;ddr;&amp;de��__</p>");
        }
Beispiel #9
0
        public void TestEmphasisAndHtmlEntity()
        {
            var markdownText = "*Unlimited-Fun&#174;*&#174;";

            TestParser.TestSpec(markdownText, "<p><em>Unlimited-Fun®</em>®</p>");
        }
Beispiel #10
0
 public static void TestSpec(string markdownText, string expected, string extensions, string context = null)
 {
     TestParser.TestSpec(markdownText, expected, extensions, plainText: true, context: context);
 }
Beispiel #11
0
 public void TestAltTextIsCorrectlyEscaped()
 {
     TestParser.TestSpec(
         @"![This is image alt text with quotation ' and double quotation ""hello"" world](girl.png)",
         @"<p><img src=""girl.png"" alt=""This is image alt text with quotation ' and double quotation &quot;hello&quot; world"" /></p>");
 }
 public void SubscriptAndStrikethrough_Double()
 {
     TestParser.TestSpec("~~foo~~", "<p><del>foo</del></p>", new MarkdownPipelineBuilder().UseEmphasisExtras(EmphasisExtraOptions.Strikethrough | EmphasisExtraOptions.Subscript).Build());
 }
 public void OnlyStrikethrough_Single()
 {
     TestParser.TestSpec("~foo~", "<p>~foo~</p>", new MarkdownPipelineBuilder().UseEmphasisExtras(EmphasisExtraOptions.Strikethrough).Build());
 }
Beispiel #14
0
 public static void TestSpec(string markdownText, string expected, string extensions)
 {
     TestParser.TestSpec(markdownText, expected, extensions, plainText: true);
 }
 public void OnlySubscript_Double()
 {
     TestParser.TestSpec("~~foo~~", "<p><sub><sub>foo</sub></sub></p>", new MarkdownPipelineBuilder().UseEmphasisExtras(EmphasisExtraOptions.Subscript).Build());
 }
Beispiel #16
0
 public void NormalStrongNormal()
 {
     TestParser.TestSpec("normal ***Strong emphasis*** normal", "<p>normal <strong><em>Strong emphasis</em></strong> normal</p>", "");
 }
Beispiel #17
0
 public void TestEmphasis(string markdown, string expectedHtml)
 {
     TestParser.TestSpec(markdown, "<p>" + expectedHtml + "</p>", Pipeline);
 }
Beispiel #18
0
 public void TestPlainWithExtensions(string markdownText, string expected, string extensions)
 {
     TestParser.TestSpec(markdownText, expected, extensions, true);
 }
Beispiel #19
0
 public void TestStandardUriEscape()
 {
     TestParser.TestSpec(@"![你好](你好.png)", "<p><img src=\"你好.png\" alt=\"你好\" /></p>", "nonascii-noescape");
 }
Beispiel #20
0
 public void TestBugEmphAttribute()
 {
     // https://github.com/lunet-io/markdig/issues/108
     TestParser.TestSpec(@"*test*{name=value}", "<p><em name=\"value\">test</em></p>", "advanced");
 }
Beispiel #21
0
 public void TestHtmlh4Bug()
 {
     TestParser.TestSpec(@"<h4>foobar</h4>", @"<h4>foobar</h4>");
 }
Beispiel #22
0
 public void TestUnicodeInDomainNameOfLinkReferenceDefinition()
 {
     TestParser.TestSpec("[Foo]\n\n[Foo]: http://ünicode.com", "<p><a href=\"http://xn--nicode-2ya.com\">Foo</a></p>");
 }