From e6e62388b92df5fe862b9628dfa34a60b1ec918e Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Sun, 10 May 2026 16:08:15 -0500 Subject: [PATCH] Added functionality to wrap grids and multi-line text into tables so they can be resized nicely --- KfChatDotNetBot/Extensions/Extensions.cs | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/KfChatDotNetBot/Extensions/Extensions.cs b/KfChatDotNetBot/Extensions/Extensions.cs index 35f4191..18ec3b7 100644 --- a/KfChatDotNetBot/Extensions/Extensions.cs +++ b/KfChatDotNetBot/Extensions/Extensions.cs @@ -137,4 +137,41 @@ public static class Extensions { return $"@{user.KfUsername}"; } + + /// + /// Format a grid of equally spaced text into a table so it can be shrunk safely by prepending a [size] tag + /// + /// Grid you want to format + /// + public static string GridToTable(this string s) + { + var table = "[table width=\"1%\"]"; + foreach (var row in s.Split(["[br]", "[BR]", "\n"], StringSplitOptions.None)) + { + table += "[tr]"; + table = row.ToCharArray().Aggregate(table, (current, glyph) => current + $"[td]{glyph}[/td]"); + table += "[/tr]"; + } + + table += "[/table]"; + return table; + } + + /// + /// Format a string with multiple lines of text into a table so it can be shrunk without ugly spacing issues by prepending a [size] tag + /// + /// Multi-line text you want to format + /// + public static string MultilineToTable(this string s) + { + // No width on this one or it'll wrap text + var table = "[table]"; + // Never use a th instead of a tr as it has a more prominent text style + foreach (var row in s.Split(["[br]", "[BR]", "\n"], StringSplitOptions.None)) + { + table += $"[tr][td]{row}[/td][/tr]"; + } + table += "[/table]"; + return table; + } } \ No newline at end of file