chore: run format

This commit is contained in:
Vlad Frangu
2025-10-05 16:13:56 +03:00
parent 2a712d4909
commit 8dc1692d87
189 changed files with 3172 additions and 916 deletions

View File

@@ -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);
}
});
});

View File

@@ -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 '\\_\\_';
});
}