Skip to content

Commit

Permalink
StripMarkdown will strip hyphens now.
Browse files Browse the repository at this point in the history
StripMarkDown is renamed to StripMarkdown.
  • Loading branch information
gehongyan committed May 22, 2024
1 parent 4af3f1c commit 0728562
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/Kook.Net.Core/Format.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,18 @@ public static string BlockQuote(this string? text, bool sanitize = true)
return result.ToString();
}

/// <inheritdoc cref="M:Kook.Format.StripMarkdown(System.String)" />
[Obsolete("Use StripMarkdown instead.")]
public static string StripMarkDown(this string text) => StripMarkdown(text);

/// <summary>
/// Remove Kook supported markdown from text.
/// </summary>
/// <param name="text">The to remove markdown from.</param>
/// <returns>Gets the unformatted text.</returns>
public static string StripMarkDown(this string text) =>
public static string StripMarkdown(this string text) =>
// Remove KOOK supported markdown
Regex.Replace(text, @"(\*|\(ins\)|\(spl\)|`|~|>|\\)", "", RegexOptions.Compiled);
Regex.Replace(text, @"\*|\(ins\)|\(spl\)|`|~|>|\\|-{2,}", "", RegexOptions.Compiled);

/// <summary>
/// Formats a user's username + identify number while maintaining bidirectional unicode
Expand Down
2 changes: 1 addition & 1 deletion src/Kook.Net.Rest/Entities/Messages/MessageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public static string SanitizeMessage(IMessage message)
string newContent = MentionUtils.Resolve(message, 0,
TagHandling.FullName, TagHandling.FullName, TagHandling.FullName,
TagHandling.FullName, TagHandling.FullName);
return newContent.StripMarkDown();
return newContent.StripMarkdown();
}

public static ImmutableArray<ITag> ParseTags(string text, IMessageChannel? channel, IGuild? guild,
Expand Down
3 changes: 2 additions & 1 deletion test/Kook.Net.Tests.Unit/FormatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ public void Code()
[InlineData(">>uwu", "uwu")]
[InlineData("```uwu```", "uwu")]
[InlineData("~uwu~", "uwu")]
[InlineData("uwu\n---\nuwu", "uwu\n\nuwu")]
[InlineData("(ins)uwu(ins)", "uwu")]
[InlineData("(spl)uwu(spl)", "uwu")]
[InlineData("berries and *Cream**, I'm a little lad who loves berries and cream",
"berries and Cream, I'm a little lad who loves berries and cream")]
public void StripMarkdown(string input, string expected)
{
string test = input.StripMarkDown();
string test = input.StripMarkdown();
Assert.Equal(expected, test);
}
}

0 comments on commit 0728562

Please sign in to comment.