Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/extensions/Statiq.Markdown/EscapeAt/EscapeAtExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
25 changes: 25 additions & 0 deletions tests/extensions/Statiq.Markdown.Tests/RenderMarkdownFixture.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 = @"<p>paragraph 1</p>[newline]<p>paragraph 2</p>[newline]";

// When
TestDocument result = await ExecuteAsync(document, markdown).SingleAsync();

// Then
result.Content.ShouldBe(expected, StringCompareShould.IgnoreLineEndings);
}

[Test]
public async Task ShouldPassThroughSlash()
{
Expand Down