diff --git a/src/extensions/Statiq.Markdown/EscapeAt/EscapeAtExtension.cs b/src/extensions/Statiq.Markdown/EscapeAt/EscapeAtExtension.cs index 81344a266..1533b01dd 100644 --- a/src/extensions/Statiq.Markdown/EscapeAt/EscapeAtExtension.cs +++ b/src/extensions/Statiq.Markdown/EscapeAt/EscapeAtExtension.cs @@ -15,7 +15,14 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) { renderer.ObjectRenderers.AddIfNotAlready(new EscapeAtInlineRenderer()); HtmlRenderer htmlRenderer = (HtmlRenderer)renderer; + + // Setting the Writer for the HTML renderer will reset the new line character to the Markdig default "\n" + // If we've modified the intended newline character (e.g., via the Markdig ConfigureNewLineExtension), + // we'll need to preserve that setting. + string newLine = htmlRenderer.Writer.NewLine; + htmlRenderer.Writer = new EscapeAtWriter(htmlRenderer.Writer); + htmlRenderer.Writer.NewLine = newLine; } } } \ No newline at end of file diff --git a/tests/extensions/Statiq.Markdown.Tests/RenderMarkdownFixture.cs b/tests/extensions/Statiq.Markdown.Tests/RenderMarkdownFixture.cs index 97da5f75a..1b7748fab 100644 --- a/tests/extensions/Statiq.Markdown.Tests/RenderMarkdownFixture.cs +++ b/tests/extensions/Statiq.Markdown.Tests/RenderMarkdownFixture.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Markdig.Extensions.TextRenderer; using NUnit.Framework; using Shouldly; using Statiq.Common; @@ -474,6 +475,30 @@ public async Task ShouldNotEscapeAtInMailToLink() result.Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings); } + [Test] + public async Task EscapeAtShouldPreserveNewLineConfiguration() + { + // Given + const string input = @"paragraph 1 + +paragraph 2 +"; + + TestDocument document = new TestDocument(input); + RenderMarkdown markdown = new RenderMarkdown(); + + // Configure a "newline" that no one actually uses so it's easy to verify + markdown.UseExtension(new ConfigureNewLineExtension("[newline]")); + + const string expected = @"

paragraph 1

[newline]

paragraph 2

[newline]"; + + // When + TestDocument result = await ExecuteAsync(document, markdown).SingleAsync(); + + // Then + result.Content.ShouldBe(expected, StringCompareShould.IgnoreLineEndings); + } + [Test] public async Task ShouldPassThroughSlash() {