Add Markdown.Escape method

This commit is contained in:
Patrik Svensson
2020-10-19 20:48:23 +02:00
committed by Patrik Svensson
parent 70fc14e9cd
commit 1410cba6c5
5 changed files with 54 additions and 8 deletions

View File

@ -199,7 +199,7 @@ namespace Spectre.Console
if (ShowHeader)
{
var heading = new DateTime(Year, Month, Day).ToString("Y", culture).SafeMarkup();
var heading = new DateTime(Year, Month, Day).ToString("Y", culture).EscapeMarkup();
table.Heading = new Title(heading, HeaderStyle);
}

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Spectre.Console.Internal;
using Spectre.Console.Rendering;
@ -46,5 +47,20 @@ namespace Spectre.Console
{
return ((IRenderable)_paragraph).Render(context, maxWidth);
}
/// <summary>
/// Escapes text so that it wont be interpreted as markup.
/// </summary>
/// <param name="text">The text to escape.</param>
/// <returns>A string that is safe to use in markup.</returns>
public static string Escape(string text)
{
if (text is null)
{
throw new ArgumentNullException(nameof(text));
}
return text.EscapeMarkup();
}
}
}