REFACTOR: unify naming of only emoji (#8741)
This commit is contained in:
parent
28d09227f5
commit
3b5a6c9895
|
@ -241,7 +241,7 @@ function applyEmoji(
|
||||||
result[result.length - 1].type === "emoji" &&
|
result[result.length - 1].type === "emoji" &&
|
||||||
result.filter(r => r.type === "emoji").length <= 3
|
result.filter(r => r.type === "emoji").length <= 3
|
||||||
) {
|
) {
|
||||||
let allEmojiLine = true;
|
let onlyEmojiLine = true;
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
|
||||||
const checkNextToken = t => {
|
const checkNextToken = t => {
|
||||||
|
@ -250,7 +250,7 @@ function applyEmoji(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!["emoji", "text"].includes(t.type)) {
|
if (!["emoji", "text"].includes(t.type)) {
|
||||||
allEmojiLine = false;
|
onlyEmojiLine = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// a text token should always have an emoji before
|
// a text token should always have an emoji before
|
||||||
|
@ -260,11 +260,11 @@ function applyEmoji(
|
||||||
((result[index - 1] && result[index - 1].type !== "emoji") ||
|
((result[index - 1] && result[index - 1].type !== "emoji") ||
|
||||||
t.content !== " ")
|
t.content !== " ")
|
||||||
) {
|
) {
|
||||||
allEmojiLine = false;
|
onlyEmojiLine = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// exit as soon as possible
|
// exit as soon as possible
|
||||||
if (allEmojiLine) {
|
if (onlyEmojiLine) {
|
||||||
index += 1;
|
index += 1;
|
||||||
checkNextToken(result[index]);
|
checkNextToken(result[index]);
|
||||||
}
|
}
|
||||||
|
@ -272,10 +272,10 @@ function applyEmoji(
|
||||||
|
|
||||||
checkNextToken(result[index]);
|
checkNextToken(result[index]);
|
||||||
|
|
||||||
if (allEmojiLine) {
|
if (onlyEmojiLine) {
|
||||||
result.forEach(r => {
|
result.forEach(r => {
|
||||||
if (r.type === "emoji") {
|
if (r.type === "emoji") {
|
||||||
applyAllEmojiClass(r);
|
applyOnlyEmojiClass(r);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ function applyEmoji(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyAllEmojiClass(token) {
|
function applyOnlyEmojiClass(token) {
|
||||||
token.attrs.forEach(attr => {
|
token.attrs.forEach(attr => {
|
||||||
if (attr[0] === "class") {
|
if (attr[0] === "class") {
|
||||||
attr[1] = `${attr[1]} only-emoji`;
|
attr[1] = `${attr[1]} only-emoji`;
|
||||||
|
|
Loading…
Reference in New Issue