sforkowany z mirror/soapbox
small fix
rodzic
1962c6544e
commit
16f06cd554
|
@ -87,22 +87,21 @@ const convertEmoji = (str: string, customEmojis: any) => {
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
const popStack = (stack: string, open: boolean) => {
|
|
||||||
const ret = stack;
|
|
||||||
open = false;
|
|
||||||
stack = '';
|
|
||||||
return ret;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const emojifyText = (str: string, customEmojis = {}) => {
|
export const emojifyText = (str: string, customEmojis = {}) => {
|
||||||
let buf = '';
|
let buf = '';
|
||||||
let stack = '';
|
let stack = '';
|
||||||
let open = false;
|
let open = false;
|
||||||
|
|
||||||
|
const clearStack = () => {
|
||||||
|
buf += stack;
|
||||||
|
open = false;
|
||||||
|
stack = '';
|
||||||
|
};
|
||||||
|
|
||||||
for (const c of split(str)) {
|
for (const c of split(str)) {
|
||||||
if (c in unicodeMapping) {
|
if (c in unicodeMapping) {
|
||||||
if (open) { // unicode emoji inside colon
|
if (open) { // unicode emoji inside colon
|
||||||
buf += popStack(stack, open);
|
clearStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
buf += convertUnicode(c);
|
buf += convertUnicode(c);
|
||||||
|
@ -124,7 +123,7 @@ export const emojifyText = (str: string, customEmojis = {}) => {
|
||||||
// if the stack is non-null and we see invalid chars it's a string not emoji
|
// if the stack is non-null and we see invalid chars it's a string not emoji
|
||||||
// so we push it to the return result and clear it
|
// so we push it to the return result and clear it
|
||||||
if (!validEmojiChar(c)) {
|
if (!validEmojiChar(c)) {
|
||||||
buf += popStack(stack, open);
|
clearStack();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buf += c;
|
buf += c;
|
||||||
|
@ -140,7 +139,7 @@ export const emojifyText = (str: string, customEmojis = {}) => {
|
||||||
return buf;
|
return buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseHTML = (str: string): { text: boolean, data: string }[] => {
|
export const parseHTML = (str: string): { text: boolean, data: string }[] => {
|
||||||
const tokens = [];
|
const tokens = [];
|
||||||
let buf = '';
|
let buf = '';
|
||||||
let stack = '';
|
let stack = '';
|
||||||
|
|
Ładowanie…
Reference in New Issue