mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 10:33:30 +01:00
feat!: add escapeQuote and escapeBlockQuote (#11129)
BREAKING CHANGE: `escapeMarkdown` now escapes quotes and block quotes by default. Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
@@ -4,6 +4,13 @@
|
||||
* The options that affect what will be escaped.
|
||||
*/
|
||||
export interface EscapeMarkdownOptions {
|
||||
/**
|
||||
* Whether to escape block quotes.
|
||||
*
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
blockQuote?: boolean;
|
||||
|
||||
/**
|
||||
* Whether to escape bold text.
|
||||
*
|
||||
@@ -80,6 +87,13 @@ export interface EscapeMarkdownOptions {
|
||||
*/
|
||||
numberedList?: boolean;
|
||||
|
||||
/**
|
||||
* Whether to escape block quotes.
|
||||
*
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
quote?: boolean;
|
||||
|
||||
/**
|
||||
* Whether to escape spoilers.
|
||||
*
|
||||
@@ -124,6 +138,8 @@ export function escapeMarkdown(text: string, options: EscapeMarkdownOptions = {}
|
||||
bulletedList = true,
|
||||
numberedList = true,
|
||||
maskedLink = true,
|
||||
blockQuote = true,
|
||||
quote = true,
|
||||
} = options;
|
||||
|
||||
if (!codeBlockContent) {
|
||||
@@ -144,6 +160,8 @@ export function escapeMarkdown(text: string, options: EscapeMarkdownOptions = {}
|
||||
bulletedList,
|
||||
numberedList,
|
||||
maskedLink,
|
||||
blockQuote,
|
||||
quote,
|
||||
});
|
||||
})
|
||||
.join(codeBlock ? '\\`\\`\\`' : '```');
|
||||
@@ -166,6 +184,8 @@ export function escapeMarkdown(text: string, options: EscapeMarkdownOptions = {}
|
||||
bulletedList,
|
||||
numberedList,
|
||||
maskedLink,
|
||||
blockQuote,
|
||||
quote,
|
||||
});
|
||||
})
|
||||
.join(inlineCode ? '\\`' : '`');
|
||||
@@ -184,6 +204,8 @@ export function escapeMarkdown(text: string, options: EscapeMarkdownOptions = {}
|
||||
if (bulletedList) res = escapeBulletedList(res);
|
||||
if (numberedList) res = escapeNumberedList(res);
|
||||
if (maskedLink) res = escapeMaskedLink(res);
|
||||
if (quote) res = escapeQuote(res);
|
||||
if (blockQuote) res = escapeBlockQuote(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -311,3 +333,21 @@ export function escapeNumberedList(text: string): string {
|
||||
export function escapeMaskedLink(text: string): string {
|
||||
return text.replaceAll(/\[.+]\(.+\)/gm, '\\$&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes quote characters in a string.
|
||||
*
|
||||
* @param text - Content to escape
|
||||
*/
|
||||
export function escapeQuote(text: string): string {
|
||||
return text.replaceAll(/^(\s*)>(\s+)/gm, '$1\\>$2');
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes block quote characters in a string.
|
||||
*
|
||||
* @param text - Content to escape
|
||||
*/
|
||||
export function escapeBlockQuote(text: string): string {
|
||||
return text.replaceAll(/^(\s*)>>>(\s+)/gm, '$1\\>>>$2');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user