Add documentation for discord/sanitizing.rs module and add a few more characters to escape in SanitizeDiscordMarkdown

This commit is contained in:
2025-08-13 00:27:35 -03:00
parent d7b8138606
commit 6ba65eef71
+13 -1
View File
@@ -1,4 +1,15 @@
//! Utilities for sanitizing Discord messages (removing markdown from user input).
/// Escapes Discord markdown in a string.
pub trait SanitizeDiscordMarkdown {
/// Escapes Discord markdown in a string.
///
/// Arguments:
/// * `hard` - If `false`, it'll only escape mentions and pings. Otherwise, it'll also escape
/// generic markdown like headers and code blocks.
///
/// Returns:
/// [`String`] - The sanitized string.
fn sanitize(&self, hard: bool) -> String;
}
@@ -14,7 +25,8 @@ where
for ch in input.chars() {
match ch {
'\\' | '*' | '_' | '~' | '`' | '>' | '<' | '|' | '#' => {
'\\' | '*' | '_' | '~' | '`' | '>' | '<' | '|' | '#' | '[' | ']' | '/'
| '(' | ')' => {
escaped.push('\\');
escaped.push(ch);
}