Skip to content

Commit 53becfc

Browse files
committed
Add StringUtils.escapeMarkdown()
1 parent 20b7768 commit 53becfc

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"respawn",
3838
"respawned",
3939
"restjson",
40+
"unescapes",
4041
"varchar"
4142
],
4243
"typescript.preferences.importModuleSpecifierEnding": "js"

src/utils/string-utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { escapeMarkdown } from 'discord.js';
12
import removeMarkdown from 'remove-markdown';
23

34
export class StringUtils {
@@ -14,6 +15,22 @@ export class StringUtils {
1415
return output;
1516
}
1617

18+
public static escapeMarkdown(input: string): string {
19+
return (
20+
escapeMarkdown(input)
21+
// Unescapes custom emojis
22+
// TODO: Update once discord.js update their escapeMarkdown()
23+
// See https://github.com/discordjs/discord.js/issues/8943
24+
.replaceAll(
25+
/<(a?):(\S+):(\d{17,20})>/g,
26+
(_match, animatedPrefix, emojiName, emojiId) => {
27+
let emojiNameUnescaped = emojiName.replaceAll(/\\/g, '');
28+
return `<${animatedPrefix}:${emojiNameUnescaped}:${emojiId}>`;
29+
}
30+
)
31+
);
32+
}
33+
1734
public static stripMarkdown(input: string): string {
1835
return removeMarkdown(input);
1936
}

0 commit comments

Comments
 (0)