mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: line with only 1 to 3 emojis will now display as large emojis
This commit is contained in:
@@ -231,9 +231,68 @@ function applyEmoji(
|
||||
result.push(text);
|
||||
}
|
||||
|
||||
// we check for a result <= 5 because we support maximum 3 large emojis
|
||||
// EMOJI SPACE EMOJI SPACE EMOJI => 5 tokens
|
||||
if (result && result.length > 0 && result.length <= 5) {
|
||||
// we ensure line starts and ends with an emoji
|
||||
// and has no more than 3 emojis
|
||||
if (
|
||||
result[0].type === "emoji" &&
|
||||
result[result.length - 1].type === "emoji" &&
|
||||
result.filter(r => r.type === "emoji").length <= 3
|
||||
) {
|
||||
let allEmojiLine = true;
|
||||
let index = 0;
|
||||
|
||||
const checkNextToken = t => {
|
||||
if (!t) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!["emoji", "text"].includes(t.type)) {
|
||||
allEmojiLine = false;
|
||||
}
|
||||
|
||||
// a text token should always have an emoji before
|
||||
// and be a space
|
||||
if (
|
||||
t.type === "text" &&
|
||||
((result[index - 1] && result[index - 1].type !== "emoji") ||
|
||||
t.content !== " ")
|
||||
) {
|
||||
allEmojiLine = false;
|
||||
}
|
||||
|
||||
// exit as soon as possible
|
||||
if (allEmojiLine) {
|
||||
index += 1;
|
||||
checkNextToken(result[index]);
|
||||
}
|
||||
};
|
||||
|
||||
checkNextToken(result[index]);
|
||||
|
||||
if (allEmojiLine) {
|
||||
result.forEach(r => {
|
||||
if (r.type === "emoji") {
|
||||
applyAllEmojiClass(r);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function applyAllEmojiClass(token) {
|
||||
token.attrs.forEach(attr => {
|
||||
if (attr[0] === "class") {
|
||||
attr[1] = `${attr[1]} only-emoji`;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function setup(helper) {
|
||||
helper.registerOptions((opts, siteSettings, state) => {
|
||||
opts.features.emoji = !state.disableEmojis && !!siteSettings.enable_emoji;
|
||||
@@ -257,5 +316,10 @@ export function setup(helper) {
|
||||
);
|
||||
});
|
||||
|
||||
helper.whiteList(["img[class=emoji]", "img[class=emoji emoji-custom]"]);
|
||||
helper.whiteList([
|
||||
"img[class=emoji]",
|
||||
"img[class=emoji emoji-custom]",
|
||||
"img[class=emoji emoji-custom only-emoji]",
|
||||
"img[class=emoji only-emoji]"
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user