Browse Source

Merge pull request #250 from FiniteReality/issue/249

Add Sanitize function to escape Markdown
tags/1.0-rc
RogueException GitHub 8 years ago
parent
commit
8b67b765c4
1 changed files with 13 additions and 0 deletions
  1. +13
    -0
      src/Discord.Net/Format.cs

+ 13
- 0
src/Discord.Net/Format.cs View File

@@ -2,6 +2,9 @@
{
public static class Format
{
// Characters which need escaping
private static string[] SensitiveCharacters = { "*", "_", "~", "`", "\\" };

/// <summary> Returns a markdown-formatted string with bold formatting. </summary>
public static string Bold(string text) => $"**{text}**";
/// <summary> Returns a markdown-formatted string with italics formatting. </summary>
@@ -19,5 +22,15 @@
else
return $"`{text}`";
}

/// <summary> Sanitizes the string, safely escaping any Markdown sequences. </summary>
public static string Sanitize(string text)
{
foreach (string unsafeChar in SensitiveCharacters)
{
text = text.Replace(unsafeChar, $"\\{unsafeChar}");
}
return text;
}
}
}

Loading…
Cancel
Save