namespace Discord { public static class Format { // Characters which need escaping private static string[] SensitiveCharacters = { "\\", "*", "_", "~", "`" }; /// Returns a markdown-formatted string with bold formatting. public static string Bold(string text) => $"**{text}**"; /// Returns a markdown-formatted string with italics formatting. public static string Italics(string text) => $"*{text}*"; /// Returns a markdown-formatted string with underline formatting. public static string Underline(string text) => $"__{text}__"; /// Returns a markdown-formatted string with strikethrough formatting. public static string Strikethrough(string text) => $"~~{text}~~"; /// Returns a markdown-formatted string with codeblock formatting. public static string Code(string text, string language = null) { if (language != null || text.Contains("\n")) return $"```{language ?? ""}\n{text}\n```"; else return $"`{text}`"; } /// Sanitizes the string, safely escaping any Markdown sequences. public static string Sanitize(string text) { foreach (string unsafeChar in SensitiveCharacters) text = text.Replace(unsafeChar, $"\\{unsafeChar}"); return text; } } }