Skip to content

Commit 6f114aa

Browse files
committed
Added a EscapeAtInMarkdown setting that can control @ escaping in Markdown files on a file-by-file basis (#254)
1 parent 040e69f commit 6f114aa

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

RELEASE.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# 1.0.0-beta.67
22

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

67
# 1.0.0-beta.66
78

src/extensions/Statiq.Markdown/MarkdownKeys.cs

+7
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,12 @@ public static class MarkdownKeys
88
/// <type cref="string" />
99
/// <type cref="T:string[]" />
1010
public const string MarkdownExtensions = nameof(MarkdownExtensions);
11+
12+
/// <summary>
13+
/// Controls whether the <c>@</c> character should be escaped. This takes precedence over the
14+
/// <see cref="RenderMarkdown.EscapeAt"/> method of the module if defined.
15+
/// </summary>
16+
/// <type cref="bool" />
17+
public const string EscapeAtInMarkdown = nameof(EscapeAtInMarkdown);
1118
}
1219
}

src/extensions/Statiq.Markdown/RenderMarkdown.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ protected override async Task<IEnumerable<IDocument>> ExecuteInputAsync(IDocumen
276276
}
277277

278278
// Add the @ escaping extension if escaping @ symbols
279-
if (_escapeAt)
279+
bool escapeAt = input.ContainsKey(MarkdownKeys.EscapeAtInMarkdown)
280+
? input.GetBool(MarkdownKeys.EscapeAtInMarkdown)
281+
: _escapeAt;
282+
if (escapeAt)
280283
{
281284
if (extensions == _extensions)
282285
{
@@ -300,7 +303,7 @@ protected override async Task<IEnumerable<IDocument>> ExecuteInputAsync(IDocumen
300303
writer,
301304
_prependLinkRoot,
302305
_passThroughRawFence,
303-
_escapeAt,
306+
escapeAt,
304307
_configuration,
305308
extensions);
306309
if (markdownDocument is null)

tests/extensions/Statiq.Markdown.Tests/RenderMarkdownFixture.cs

+40
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,46 @@ public async Task ShouldNotEscapeAtWhenFalse()
200200
result.Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings);
201201
}
202202

203+
[Test]
204+
public async Task ShouldEscapeAtWhenOverriddenByMetadata()
205+
{
206+
// Given
207+
const string input = "Looking @Good, @Man!";
208+
const string output = @"<p>Looking &#64;Good, &#64;Man!</p>
209+
";
210+
TestDocument document = new TestDocument(input)
211+
{
212+
{ MarkdownKeys.EscapeAtInMarkdown, true }
213+
};
214+
RenderMarkdown markdown = new RenderMarkdown().EscapeAt(false);
215+
216+
// When
217+
TestDocument result = await ExecuteAsync(document, markdown).SingleAsync();
218+
219+
// Then
220+
result.Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings);
221+
}
222+
223+
[Test]
224+
public async Task ShouldNotEscapeAtWhenOverriddenByMetadata()
225+
{
226+
// Given
227+
const string input = "Looking @Good, @Man!";
228+
const string output = @"<p>Looking @Good, @Man!</p>
229+
";
230+
TestDocument document = new TestDocument(input)
231+
{
232+
{ MarkdownKeys.EscapeAtInMarkdown, false }
233+
};
234+
RenderMarkdown markdown = new RenderMarkdown().EscapeAt();
235+
236+
// When
237+
TestDocument result = await ExecuteAsync(document, markdown).SingleAsync();
238+
239+
// Then
240+
result.Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings);
241+
}
242+
203243
[Test]
204244
public async Task ShouldNotEscapeAtWhenEscapedBySlash()
205245
{

0 commit comments

Comments
 (0)