mirror of
https://github.com/zotero/zotero.git
synced 2026-09-07 08:26:14 +00:00
Add support for displaying country flag emojis in the Items List (#5700)
This commit is contained in:
parent
bed1d1ff35
commit
d1d4065dae
3 changed files with 13 additions and 6 deletions
|
|
@ -842,10 +842,9 @@ Zotero.Tags = new function () {
|
|||
|
||||
// Return the first sequence of emojis from a string
|
||||
this.extractEmojiForItemsList = function (str) {
|
||||
// Split by anything that is not an emoji, Zero Width Joiner, or Variation Selector-16
|
||||
// And return first continuous span of emojis
|
||||
let re = /[^\p{Extended_Pictographic}\u200D\uFE0F]+/gu;
|
||||
return str.split(re).filter(Boolean)[0] || null;
|
||||
// Either match RGI_Emoji (which includes country flags) or any character followed by the Variation Selector-16
|
||||
let re = /(?:\p{RGI_Emoji}(?!\uFE0F)|.\uFE0F)+/gv;
|
||||
return str.match(re)?.[0] || null;
|
||||
};
|
||||
|
||||
// Used as parameter for .sort() method on an array of tags
|
||||
|
|
|
|||
|
|
@ -388,13 +388,13 @@ Zotero.Utilities.Internal = {
|
|||
},
|
||||
|
||||
containsEmoji: function (str) {
|
||||
let re = /\p{Extended_Pictographic}/gu;
|
||||
let re = /\p{RGI_Emoji}/gv;
|
||||
return !!str.match(re);
|
||||
},
|
||||
|
||||
includesEmoji: function (str) {
|
||||
// Remove emoji, Zero Width Joiner, and Variation Selector-16 and compare lengths
|
||||
const re = /\p{Extended_Pictographic}|\u200D|\uFE0F/gu;
|
||||
const re = /(?:\p{RGI_Emoji}(?!\uFE0F)|.\uFE0F)+/gv;
|
||||
return str.replace(re, '').length !== str.length;
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -238,6 +238,14 @@ describe("Zotero.Tags", function () {
|
|||
it("should return first emoji span for text with an emoji made up of multiple characters with ZWJ", function () {
|
||||
assert.equal(Zotero.Tags.extractEmojiForItemsList("We are 👨🌾👨🌾. And I am a 👨🏫."), "👨🌾👨🌾");
|
||||
});
|
||||
|
||||
it("should return first emoji span that contains RGI country flags", function () {
|
||||
assert.equal(Zotero.Tags.extractEmojiForItemsList("Hello country flags 🇱🇺🇮🇪"), "🇱🇺🇮🇪");
|
||||
});
|
||||
|
||||
it("should return first emoji span that contains regional flags", function () {
|
||||
assert.equal(Zotero.Tags.extractEmojiForItemsList("Hello England and Scotland: 🏴🏴"), "🏴🏴");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#compareTagsOrder()", function () {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue