Skip to content

Commit

Permalink
Replace emoji img tag by emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrochlore committed Sep 16, 2021
1 parent d5234f7 commit 3810a63
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,25 @@ export function trimByChar(str: string, char: string) {
: str.substring(first, str.length - last);
}

export function replaceEmojiImgTagByEmoji(input: string) {
if (input === null) return null;

// <img[^>]*?alt\s*=\s*[""']?(?<emoji>[^'"" >]+?)[ '""][^>]*?>
let strRegex =
'<img[^>]*?alt\\s*=\\s*[""\']?(?<emoji>[^\'"" >]+?)[ \'""][^>]*?>';
// console.log(strRegex);
let regex = new RegExp(strRegex, "g");

let output = input.replace(regex, (...args) => {
let groups = args[args.length - 1];
if (groups && groups.emoji) {
return groups.emoji.trim();
}
return "";
});

return output;
}
// Parsing
export function parseFloatFromAny(
toParse: any,
Expand Down
11 changes: 11 additions & 0 deletions src/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,10 @@ function getStringArrayFromInput(
return errorMessage;
}

for (let ind = 0; ind < array.length; ind++) {
array[ind] = helper.replaceEmojiImgTagByEmoji(array[ind]);
}

return array;
}

Expand Down Expand Up @@ -631,6 +635,10 @@ function getStringArray(name: string, input: any): Array<string> | string {
return errorMessage;
}

for (let ind = 0; ind < strArray.length; ind++) {
strArray[ind] = helper.replaceEmojiImgTagByEmoji(strArray[ind]);
}

return strArray;
}

Expand Down Expand Up @@ -943,6 +951,9 @@ export function getRenderInfoFromYaml(
} else {
errorMessage = "Invalid search target (searchTarget)";
}
for (let ind = 0; ind < searchTarget.length; ind++) {
searchTarget[ind] = helper.replaceEmojiImgTagByEmoji(searchTarget[ind]);
}
// console.log(searchTarget);

if (errorMessage !== "") {
Expand Down

0 comments on commit 3810a63

Please sign in to comment.