Skip to content

Commit

Permalink
Added a EscapeAtInMarkdown setting that can control @ escaping in…
Browse files Browse the repository at this point in the history
… Markdown files on a file-by-file basis (#254)
  • Loading branch information
daveaglick committed May 19, 2023
1 parent 040e69f commit 6f114aa
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
3 changes: 2 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# 1.0.0-beta.67

- Fixed a bug that still resulted in file cleaning even when `CleanMode.None` is set (I.e. `--noclean`).
- `RenderMarkdown` no longer escapes `@` characters inside `mailto` links (#254).
- `RenderMarkdown` no longer escapes `@` characters inside `mailto` links (#254).
- Added a `EscapeAtInMarkdown` setting that can control `@` escaping in Markdown files by the `RenderMarkdown` module on a file-by-file basis (#254).

# 1.0.0-beta.66

Expand Down
7 changes: 7 additions & 0 deletions src/extensions/Statiq.Markdown/MarkdownKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@ public static class MarkdownKeys
/// <type cref="string" />
/// <type cref="T:string[]" />
public const string MarkdownExtensions = nameof(MarkdownExtensions);

/// <summary>
/// Controls whether the <c>@</c> character should be escaped. This takes precedence over the
/// <see cref="RenderMarkdown.EscapeAt"/> method of the module if defined.
/// </summary>
/// <type cref="bool" />
public const string EscapeAtInMarkdown = nameof(EscapeAtInMarkdown);
}
}
7 changes: 5 additions & 2 deletions src/extensions/Statiq.Markdown/RenderMarkdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ protected override async Task<IEnumerable<IDocument>> ExecuteInputAsync(IDocumen
}

// Add the @ escaping extension if escaping @ symbols
if (_escapeAt)
bool escapeAt = input.ContainsKey(MarkdownKeys.EscapeAtInMarkdown)
? input.GetBool(MarkdownKeys.EscapeAtInMarkdown)
: _escapeAt;
if (escapeAt)
{
if (extensions == _extensions)
{
Expand All @@ -300,7 +303,7 @@ protected override async Task<IEnumerable<IDocument>> ExecuteInputAsync(IDocumen
writer,
_prependLinkRoot,
_passThroughRawFence,
_escapeAt,
escapeAt,
_configuration,
extensions);
if (markdownDocument is null)
Expand Down
40 changes: 40 additions & 0 deletions tests/extensions/Statiq.Markdown.Tests/RenderMarkdownFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,46 @@ public async Task ShouldNotEscapeAtWhenFalse()
result.Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings);
}

[Test]
public async Task ShouldEscapeAtWhenOverriddenByMetadata()
{
// Given
const string input = "Looking @Good, @Man!";
const string output = @"<p>Looking &#64;Good, &#64;Man!</p>
";
TestDocument document = new TestDocument(input)
{
{ MarkdownKeys.EscapeAtInMarkdown, true }
};
RenderMarkdown markdown = new RenderMarkdown().EscapeAt(false);

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

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

[Test]
public async Task ShouldNotEscapeAtWhenOverriddenByMetadata()
{
// Given
const string input = "Looking @Good, @Man!";
const string output = @"<p>Looking @Good, @Man!</p>
";
TestDocument document = new TestDocument(input)
{
{ MarkdownKeys.EscapeAtInMarkdown, false }
};
RenderMarkdown markdown = new RenderMarkdown().EscapeAt();

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

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

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

0 comments on commit 6f114aa

Please sign in to comment.