]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/emoji.js
1 import { unicodeMapping
} from './emojione_light';
2 import Trie
from 'substring-trie';
4 const trie
= new Trie(Object
.keys(unicodeMapping
));
6 const emojify
= (str
, customEmojis
= {}) => {
10 while (i
< str
.length
&& (tag
= '<&:'.indexOf(str
[i
])) === -1 && !(match
= trie
.search(str
.slice(i
)))) {
11 i
+= str
.codePointAt(i
) < 65536 ? 1 : 2;
16 let tagend
= str
.indexOf('>;:'[tag
], i
+ 1) + 1;
20 const shortname
= str
.slice(i
, tagend
);
21 const lt
= str
.indexOf('<', i
+ 1);
22 if ((lt
=== -1 || lt
>= tagend
) && shortname
in customEmojis
) {
23 rtn
+= str
.slice(0, i
) + `<img draggable="false" class="emojione" alt="${shortname}" title="${shortname}" src="${customEmojis[shortname]}" />`;
24 str
= str
.slice(tagend
);
26 rtn
+= str
.slice(0, i
+ 1);
27 str
= str
.slice(i
+ 1);
30 rtn
+= str
.slice(0, tagend
);
31 str
= str
.slice(tagend
);
34 const [filename
, shortCode
] = unicodeMapping
[match
];
35 rtn
+= str
.slice(0, i
) + `<img draggable="false" class="emojione" alt="${match}" title=":${shortCode}:" src="/emoji/${filename}.svg" />`;
36 str
= str
.slice(i
+ match
.length
);
42 export default emojify
;
This page took 0.076021 seconds and 4 git commands to generate.