mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
chore: run format
This commit is contained in:
@@ -85,7 +85,9 @@ describe('Markdown escapers', () => {
|
||||
});
|
||||
|
||||
test('url', () => {
|
||||
for (const url of testURLs) expect(escapeItalic(url)).toBe(url);
|
||||
for (const url of testURLs) {
|
||||
expect(escapeItalic(url)).toBe(url);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -108,7 +110,9 @@ describe('Markdown escapers', () => {
|
||||
});
|
||||
|
||||
test('url', () => {
|
||||
for (const url of testURLs) expect(escapeUnderline(url)).toBe(url);
|
||||
for (const url of testURLs) {
|
||||
expect(escapeUnderline(url)).toBe(url);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -130,7 +130,10 @@ export function escapeMarkdown(text: string, options: EscapeMarkdownOptions = {}
|
||||
return text
|
||||
.split('```')
|
||||
.map((subString, index, array) => {
|
||||
if (index % 2 && index !== array.length - 1) return subString;
|
||||
if (index % 2 && index !== array.length - 1) {
|
||||
return subString;
|
||||
}
|
||||
|
||||
return escapeMarkdown(subString, {
|
||||
inlineCode,
|
||||
bold,
|
||||
@@ -153,7 +156,10 @@ export function escapeMarkdown(text: string, options: EscapeMarkdownOptions = {}
|
||||
return text
|
||||
.split(/(?<=^|[^`])`(?=[^`]|$)/g)
|
||||
.map((subString, index, array) => {
|
||||
if (index % 2 && index !== array.length - 1) return subString;
|
||||
if (index % 2 && index !== array.length - 1) {
|
||||
return subString;
|
||||
}
|
||||
|
||||
return escapeMarkdown(subString, {
|
||||
codeBlock,
|
||||
bold,
|
||||
@@ -172,18 +178,54 @@ export function escapeMarkdown(text: string, options: EscapeMarkdownOptions = {}
|
||||
}
|
||||
|
||||
let res = text;
|
||||
if (escape) res = escapeEscape(res);
|
||||
if (inlineCode) res = escapeInlineCode(res);
|
||||
if (codeBlock) res = escapeCodeBlock(res);
|
||||
if (italic) res = escapeItalic(res);
|
||||
if (bold) res = escapeBold(res);
|
||||
if (underline) res = escapeUnderline(res);
|
||||
if (strikethrough) res = escapeStrikethrough(res);
|
||||
if (spoiler) res = escapeSpoiler(res);
|
||||
if (heading) res = escapeHeading(res);
|
||||
if (bulletedList) res = escapeBulletedList(res);
|
||||
if (numberedList) res = escapeNumberedList(res);
|
||||
if (maskedLink) res = escapeMaskedLink(res);
|
||||
if (escape) {
|
||||
res = escapeEscape(res);
|
||||
}
|
||||
|
||||
if (inlineCode) {
|
||||
res = escapeInlineCode(res);
|
||||
}
|
||||
|
||||
if (codeBlock) {
|
||||
res = escapeCodeBlock(res);
|
||||
}
|
||||
|
||||
if (italic) {
|
||||
res = escapeItalic(res);
|
||||
}
|
||||
|
||||
if (bold) {
|
||||
res = escapeBold(res);
|
||||
}
|
||||
|
||||
if (underline) {
|
||||
res = escapeUnderline(res);
|
||||
}
|
||||
|
||||
if (strikethrough) {
|
||||
res = escapeStrikethrough(res);
|
||||
}
|
||||
|
||||
if (spoiler) {
|
||||
res = escapeSpoiler(res);
|
||||
}
|
||||
|
||||
if (heading) {
|
||||
res = escapeHeading(res);
|
||||
}
|
||||
|
||||
if (bulletedList) {
|
||||
res = escapeBulletedList(res);
|
||||
}
|
||||
|
||||
if (numberedList) {
|
||||
res = escapeNumberedList(res);
|
||||
}
|
||||
|
||||
if (maskedLink) {
|
||||
res = escapeMaskedLink(res);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -213,12 +255,18 @@ export function escapeInlineCode(text: string): string {
|
||||
export function escapeItalic(text: string): string {
|
||||
let idx = 0;
|
||||
const newText = text.replaceAll(/(?<=^|[^*])\*([^*]|\*\*|$)/g, (_, match) => {
|
||||
if (match === '**') return ++idx % 2 ? `\\*${match}` : `${match}\\*`;
|
||||
if (match === '**') {
|
||||
return ++idx % 2 ? `\\*${match}` : `${match}\\*`;
|
||||
}
|
||||
|
||||
return `\\*${match}`;
|
||||
});
|
||||
idx = 0;
|
||||
return newText.replaceAll(/(?<=^|[^_])(?<!<a?:.+|https?:\/\/\S+)_(?!:\d+>)([^_]|__|$)/g, (_, match) => {
|
||||
if (match === '__') return ++idx % 2 ? `\\_${match}` : `${match}\\_`;
|
||||
if (match === '__') {
|
||||
return ++idx % 2 ? `\\_${match}` : `${match}\\_`;
|
||||
}
|
||||
|
||||
return `\\_${match}`;
|
||||
});
|
||||
}
|
||||
@@ -231,7 +279,10 @@ export function escapeItalic(text: string): string {
|
||||
export function escapeBold(text: string): string {
|
||||
let idx = 0;
|
||||
return text.replaceAll(/\*\*(\*)?/g, (_, match) => {
|
||||
if (match) return ++idx % 2 ? `${match}\\*\\*` : `\\*\\*${match}`;
|
||||
if (match) {
|
||||
return ++idx % 2 ? `${match}\\*\\*` : `\\*\\*${match}`;
|
||||
}
|
||||
|
||||
return '\\*\\*';
|
||||
});
|
||||
}
|
||||
@@ -244,7 +295,10 @@ export function escapeBold(text: string): string {
|
||||
export function escapeUnderline(text: string): string {
|
||||
let idx = 0;
|
||||
return text.replaceAll(/(?<!<a?:.+|https?:\/\/\S+)__(_)?(?!:\d+>)/g, (_, match) => {
|
||||
if (match) return ++idx % 2 ? `${match}\\_\\_` : `\\_\\_${match}`;
|
||||
if (match) {
|
||||
return ++idx % 2 ? `${match}\\_\\_` : `\\_\\_${match}`;
|
||||
}
|
||||
|
||||
return '\\_\\_';
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user