From 0174745881783caf4e099ffdcffe4598de0a0936 Mon Sep 17 00:00:00 2001 From: Leon Schimmel Date: Tue, 14 Jan 2025 23:48:45 +0100 Subject: [PATCH] Added Header and Subtext to the Format class (#3052) --- src/Discord.Net.Core/Format.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.Core/Format.cs b/src/Discord.Net.Core/Format.cs index 04e811c7c9..6c8243fca0 100644 --- a/src/Discord.Net.Core/Format.cs +++ b/src/Discord.Net.Core/Format.cs @@ -1,3 +1,4 @@ +using System; using System.Text; using System.Text.RegularExpressions; @@ -24,11 +25,16 @@ public static class Format public static string Url(string text, string url) => $"[{text}]({url})"; /// Escapes a URL so that a preview is not generated. public static string EscapeUrl(string url) => $"<{url}>"; + /// Returns a markdown-formatted string with header formatting. + public static string Header(string text, int level = 1) + => level < 1 || level > 3 ? text : $"{new string('#', level)} {text}"; + /// Returns a markdown-formatted string with subtext formatting. + public static string Subtext(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")) + if (language is not null || text.Contains("\n")) return $"```{language ?? ""}\n{text}\n```"; else return $"`{text}`";