mirror of
https://git.lavender.software/lavender/watch-party.git
synced 2024-11-24 02:47:43 +00:00
11 lines
442 B
JavaScript
11 lines
442 B
JavaScript
|
export function emojify(text) {
|
||
|
let last = 0;
|
||
|
let nodes = [];
|
||
|
text.replace(/:([^\s:]+):/g, (match, name, index) => {
|
||
|
if(last <= index) nodes.push(document.createTextNode(text.slice(last, index)))
|
||
|
nodes.push(Object.assign(new Image(), {src: `/emojis/${name}.png`, className: "emoji", alt: name}))
|
||
|
last = index + match.length
|
||
|
})
|
||
|
if(last < text.length) nodes.push(document.createTextNode(text.slice(last)))
|
||
|
return nodes
|
||
|
}
|