<script>alert('test')</script>
", true)] + [InlineData("", "<script>alert('test')</script>
", false)] + [InlineData("", "<img src="javascript:alert('test');">
", true)] + [InlineData("", "<img src="javascript:alert('test');">
", false)] + [InlineData("", "<a href="javascript:alert('test');">
", true)] + [InlineData("", "<a href="javascript:alert('test');">
", false)] + public void EncodesHtmlInMarkdown(string originalMd, string expectedHtml, bool isMarkdigMdRenderingEnabled) + { + _featureFlagService.Setup(x => x.IsMarkdigMdRenderingEnabled()).Returns(isMarkdigMdRenderingEnabled); + Assert.Equal(expectedHtml, _markdownService.GetHtmlFromMarkdown(originalMd).Content); } [Theory] - [InlineData("", "<script>alert('test')</script>
")] - [InlineData("", "<img src="javascript:alert('test');">
")] - [InlineData("", "<a href="javascript:alert('test');">
")] - public void EncodesHtmlInMarkdown(string originalMd, string expectedHtml) + [InlineData("# Heading", "", false)] - [InlineData("[text](http://www.asp.net)", "", false)] - [InlineData("[text](badurl://www.asp.net)", "", false)] - [InlineData("![image](http://www.asp.net/fake.jpg)", "", true)] - [InlineData("![image](https://www.asp.net/fake.jpg)", "", false)] - [InlineData("![image](http://www.otherurl.net/fake.jpg)", "", true)] - public void ConvertsMarkdownToHtml(string originalMd, string expectedHtml, bool imageRewriteExpected) - { - var readMeResult = _markdownService.GetHtmlFromMarkdown(originalMd); - Assert.Equal(expectedHtml, StripNewLines(readMeResult.Content)); + [InlineData("# Heading", "<text>Blockquote</text>
\n", false, true)] + [InlineData("><text>Blockquote</text>
\n
\r\n", false, false)] + [InlineData("> ><text>Blockquote</text>
\r\n
\n", false, true)] + [InlineData("> >\n\n<text>Blockquote</text>
\n
\r\n", false, false)] + [InlineData("[text](http://www.asp.net)", "", false, true)] + [InlineData("[text](http://www.asp.net)", "", false, false)] + [InlineData("[text](badurl://www.asp.net)", "", false, true)] + [InlineData("[text](badurl://www.asp.net)", "", false, false)] + [InlineData("![image](http://www.asp.net/fake.jpg)", "", true, true)] + [InlineData("![image](http://www.asp.net/fake.jpg)", "", true, false)] + [InlineData("![image](https://www.asp.net/fake.jpg)", "", false, true)] + [InlineData("![image](https://www.asp.net/fake.jpg)", "", false, false)] + [InlineData("![image](http://www.otherurl.net/fake.jpg)", "", true, true)] + [InlineData("![image](http://www.otherurl.net/fake.jpg)", "", true, false)] + [InlineData("## License\n\tLicensed under the Apache License, Version 2.0 (the \"License\");", "> <text>Blockquote</text>
\r\n
Licensed under the Apache License, Version 2.0 (the "License");\n
", false, true)]
+ [InlineData("## License\n\tLicensed under the Apache License, Version 2.0 (the \"License\");", "Licensed under the Apache License, Version 2.0 (the "License");\n
", false, true)]
+ public void ConvertsMarkdownToHtml(string originalMd, string expectedHtml, bool imageRewriteExpected, bool isMarkdigMdRenderingEnabled)
+ {
+ _featureFlagService.Setup(x => x.IsMarkdigMdRenderingEnabled()).Returns(isMarkdigMdRenderingEnabled);
+ var readMeResult = _markdownService.GetHtmlFromMarkdown(originalMd);
+ Assert.Equal(expectedHtml, readMeResult.Content);
Assert.Equal(imageRewriteExpected, readMeResult.ImagesRewritten);
}
- private static string StripNewLines(string text)
+ [Fact]
+ public void TestToHtmlWithExtension()
+ {
+ var originalMd = "This is a paragraph\r\n with a break inside";
+ var expectedHtml = "This is a paragraph
\nwith a break inside
a | \nb | \n
---|---|
0 | \n1 | \n
a | \nb | \n
---|---|
1 | \n2 | \n
This is a test with a 😃 and a 😠 smiley
"; + _featureFlagService.Setup(x => x.IsMarkdigMdRenderingEnabled()).Returns(true); + var readMeResult = _markdownService.GetHtmlFromMarkdown(originalMd); + Assert.Equal(expectedHtml, readMeResult.Content); + Assert.Equal(false, readMeResult.ImagesRewritten); + } + + [Fact] + public void TestToHtmlWithTaskLists() + { + var originalMd = @"- [ ] Item1 +- [x] Item2 +- [ ] Item3 +- Item4"; + + var expectedHtml = "Some text
\nThis is a http://www.google.com URL and https://www.google.com
"; + _featureFlagService.Setup(x => x.IsMarkdigMdRenderingEnabled()).Returns(true); + var readMeResult = _markdownService.GetHtmlFromMarkdown(originalMd); + Assert.Equal(expectedHtml, readMeResult.Content); + Assert.Equal(false, readMeResult.ImagesRewritten); } } }