public async Task RendersMarkdownThatStartsWithIndentedCodeBlock()
        {
            var tagHelper = new MarkdownTagHelper {
                PreserveIndentation = true
            };
            var tagHelperContext = new TagHelperContext(
                new TagHelperAttributeList(),
                new Dictionary <object, object>(),
                Guid.NewGuid().ToString("N"));
            var tagHelperOutput = new TagHelperOutput(
                "markdown",
                new TagHelperAttributeList(),
                (_, _) => {
                var tagHelperContent = new DefaultTagHelperContent()
                                       .SetHtmlContent(new HtmlString(@"
    Some Code

Not Code
"));
                return(Task.FromResult(tagHelperContent));
            });
            await tagHelper.ProcessAsync(tagHelperContext, tagHelperOutput);

            Assert.Null(tagHelperOutput.TagName);
            Assert.Equal(@"<pre><code>Some Code
</code></pre>
<p>Not Code</p>
",
                         tagHelperOutput.Content.GetContent());
        }
        public async Task MarkdownTagWithChildContentShouldReturnRenderedMarkdown()
        {
            //Arrange
            var helper  = new MarkdownTagHelper();
            var context = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), Guid.NewGuid().ToString());
            var output  = new TagHelperOutput("markdown", new TagHelperAttributeList(), GetChildContent("## Banana"));

            //Act
            await helper.ProcessAsync(context, output);

            //Assert
            Assert.Null(output.TagName);
            Assert.StartsWith("<h2>Banana</h2>", output.Content.GetContent());
        }
        public async Task ArticleTagWithChildContentWithMarkdownAttributeShouldReturnRenderedMarkdown()
        {
            // arrange
            var sut = new MarkdownTagHelper();
            var hasMarkdownAttribute = true;
            var tagName = "article";

            var context = _helper.CreateContext(hasMarkdownAttribute);
            var output = _helper.CreateOutput(tagName, hasMarkdownAttribute, "# Hello");

            // act
            await sut.ProcessAsync(context, output);
            
            //assert
            Assert.Equal(tagName, output.TagName);
            Assert.StartsWith("<h1>Hello</h1>", output.Content.GetContent());
        }
        public async Task MarkdownTagWithChildContentShouldReturnRenderedMarkdown()
        {
            // arrange
            var sut = new MarkdownTagHelper();
            var hasMarkdownAttribute = false;
            var tagName = "markdown";

            var context = _helper.CreateContext("## Hello", hasMarkdownAttribute);
            var output = _helper.CreateOutput(tagName, hasMarkdownAttribute);

            // act
            await sut.ProcessAsync(context, output);

            //assert
            Assert.Equal(null, output.TagName);
            Assert.StartsWith("<h2>Hello</h2>", output.Content.GetContent());
        }
        public async Task ArticleTagWithChildContentWithMarkdownAttributeShouldReturnRenderedMarkdown()
        {
            // arrange
            var sut = new MarkdownTagHelper();
            var hasMarkdownAttribute = true;
            var tagName = "article";

            var context = _helper.CreateContext(hasMarkdownAttribute);
            var output  = _helper.CreateOutput(tagName, hasMarkdownAttribute, "# Hello");

            // act
            await sut.ProcessAsync(context, output);

            //assert
            Assert.Equal(tagName, output.TagName);
            Assert.StartsWith("<h1>Hello</h1>", output.Content.GetContent());
        }
        public async Task DivWithAttributeShouldReturnRenderedMarkdown()
        {
            //Arrange
            var helper  = new MarkdownTagHelper();
            var context = new TagHelperContext(new TagHelperAttributeList {
                new TagHelperAttribute("markdown")
            }, new Dictionary <object, object>(), Guid.NewGuid().ToString());
            var output = new TagHelperOutput("div", new TagHelperAttributeList {
                new TagHelperAttribute("markdown")
            }, GetChildContent("# Mr French"));

            //Act
            await helper.ProcessAsync(context, output);

            //Assert
            Assert.Equal("div", output.TagName);
            Assert.StartsWith("<h1>Mr French</h1>", output.Content.GetContent());
        }
        public async Task RendersHtmlFromMarkdown()
        {
            var tagHelper        = new MarkdownTagHelper();
            var tagHelperContext = new TagHelperContext(
                new TagHelperAttributeList(),
                new Dictionary <object, object>(),
                Guid.NewGuid().ToString("N"));
            var tagHelperOutput = new TagHelperOutput(
                "markdown",
                new TagHelperAttributeList(),
                (_, _) => {
                var tagHelperContent = new DefaultTagHelperContent()
                                       .SetHtmlContent(new HtmlString("*Italic*, **bold**, and `monospace`."));
                return(Task.FromResult(tagHelperContent));
            });
            await tagHelper.ProcessAsync(tagHelperContext, tagHelperOutput);

            Assert.Null(tagHelperOutput.TagName);
            Assert.Equal("<p><em>Italic</em>, <strong>bold</strong>, and <code>monospace</code>.</p>\n",
                         tagHelperOutput.Content.GetContent());
        }
        public async Task RendersSanitizedHtmlWhenAllowHtmlTrue()
        {
            var tagHelper = new MarkdownTagHelper {
                AllowHtml = true, PreserveIndentation = false
            };
            var tagHelperContext = new TagHelperContext(
                new TagHelperAttributeList(),
                new Dictionary <object, object>(),
                Guid.NewGuid().ToString("N"));
            var tagHelperOutput = new TagHelperOutput(
                "markdown",
                new TagHelperAttributeList(),
                (_, _) => {
                var tagHelperContent = new DefaultTagHelperContent()
                                       .SetHtmlContent(new HtmlString(@"
    # Title one

    Before image

    <img src onerror=alert(document.cookie)>

    After image

    ## Subject two

    Test"));
                return(Task.FromResult(tagHelperContent));
            });
            await tagHelper.ProcessAsync(tagHelperContext, tagHelperOutput);

            Assert.Null(tagHelperOutput.TagName);
            Assert.Equal(@"<h1>Title one</h1>
<p>Before image</p>
<img src="""">
<p>After image</p>
<h2>Subject two</h2>
<p>Test</p>
",
                         tagHelperOutput.Content.GetContent());
        }