Add documentation for discord/sanitizing.rs module and add a few more characters to escape in SanitizeDiscordMarkdown
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user