diff --git a/src/Extensions/DiffPaneModelExtensions.cs b/src/Extensions/DiffPaneModelExtensions.cs index ec7b8ee..1c3a098 100644 --- a/src/Extensions/DiffPaneModelExtensions.cs +++ b/src/Extensions/DiffPaneModelExtensions.cs @@ -12,17 +12,17 @@ public static class DiffPaneModelExtensions { if (line.Type is ChangeType.Deleted) { - builder.Append("- "); + builder.Append("-- "); } if (line.Type is ChangeType.Inserted) { - builder.Append("+ "); + builder.Append("++ "); } if (line.Type is not ChangeType.Imaginary) { - builder.AppendLine(line.Text); + builder.AppendLine(line.Text.SanitizeForDiffBlock()); } } diff --git a/src/Extensions/StringExtensions.cs b/src/Extensions/StringExtensions.cs index 3de05d3..13cd88a 100644 --- a/src/Extensions/StringExtensions.cs +++ b/src/Extensions/StringExtensions.cs @@ -5,6 +5,8 @@ namespace Octobot.Extensions; public static class StringExtensions { + private const string ZeroWidthSpace = "​"; + /// /// Sanitizes a string for use in by inserting zero-width spaces in between /// symbols used to format the string with block code. @@ -13,7 +15,19 @@ public static class StringExtensions /// The sanitized string that can be safely used in . private static string SanitizeForBlockCode(this string s) { - return s.Replace("```", "​`​`​`​"); + return s.Replace("```", $"{ZeroWidthSpace}`{ZeroWidthSpace}`{ZeroWidthSpace}`{ZeroWidthSpace}"); + } + + /// + /// Sanitizes a string for use in when "language" is "diff" by + /// prepending a zero-width space before the input string to prevent Discord from applying syntax highlighting. + /// + /// This does not call , you have to do so yourself if needed. + /// The string to sanitize. + /// The sanitized string that can be safely used in with "diff" as the language. + public static string SanitizeForDiffBlock(this string s) + { + return $"{ZeroWidthSpace}{s}"; } ///