2018-04-15 00:50:06 +02:00
|
|
|
import { replaceAll } from './strings'
|
2018-11-20 09:01:23 +01:00
|
|
|
import { replaceEmoji } from './replaceEmoji'
|
2018-04-15 00:50:06 +02:00
|
|
|
|
|
|
|
export function emojifyText (text, emojis, autoplayGifs) {
|
2018-11-20 09:01:23 +01:00
|
|
|
// replace native emoji with wrapped spans so we can give them the proper font-family
|
|
|
|
text = replaceEmoji(text, substring => `<span class="inline-emoji">${substring}</span>`)
|
|
|
|
|
|
|
|
// replace custom emoji
|
2018-08-20 03:03:26 +02:00
|
|
|
if (emojis) {
|
2018-04-15 00:50:06 +02:00
|
|
|
for (let emoji of emojis) {
|
|
|
|
let urlToUse = autoplayGifs ? emoji.url : emoji.static_url
|
|
|
|
let shortcodeWithColons = `:${emoji.shortcode}:`
|
|
|
|
text = replaceAll(
|
|
|
|
text,
|
|
|
|
shortcodeWithColons,
|
2018-08-20 00:23:40 +02:00
|
|
|
`<img class="inline-custom-emoji" draggable="false" src="${urlToUse}"
|
2018-04-15 00:50:06 +02:00
|
|
|
alt="${shortcodeWithColons}" title="${shortcodeWithColons}" />`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2018-11-20 09:01:23 +01:00
|
|
|
|
2018-04-15 00:50:06 +02:00
|
|
|
return text
|
|
|
|
}
|