Improved remove markdown utility

This commit is contained in:
Erik 2022-05-08 14:35:04 +03:00
parent d9476e43b7
commit 07a4fe0a11
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
3 changed files with 5 additions and 2 deletions

View File

@ -47,6 +47,7 @@
"nightbird",
"slurs",
"an alt",
"nyquil",
"lol!",
"coco",
"slur",

View File

@ -281,7 +281,7 @@ module.exports = class FilterUtility {
const diff = Math.abs(fullWord.length - match[0].length);
if (diff > 3) {
this.logger.debug(`Match length diff: ${diff} MATCH: ${match[0]} FULL: ${fullWord}`);
this.logger.debug(`Match length diff: ${diff} MATCH: ${match[0]} FULL: ${fullWord}, CONTENT: ${content}`);
continue;
}
// log += `\nMessage matched with "${reg}" in the regex list.\nMatch: ${match[0]}, Full word: ${fullWord}\nFull content: ${content}`;

View File

@ -123,6 +123,7 @@ class Util {
*/
static get formattingPatterns() {
return [
['\\|{2}(.*)\\|{2}', '$1'],
['\\*{1,3}([^*]*)\\*{1,3}', '$1'],
['_{1,3}([^_]*)_{1,3}', '$1'],
['`{1,3}([^`]*)`{1,3}', '$1'],
@ -139,7 +140,8 @@ class Util {
static removeMarkdown(content) {
if (!content) throw new Error('Missing content');
this.formattingPatterns.forEach(([pattern, replacer]) => {
content = content.replace(new RegExp(pattern, 'gu'), replacer);
const reg = new RegExp(pattern, 'gu');
while(reg.test(content)) content = content.replace(reg, replacer);
});
return content.trim();
}