2018-04-14 22:50:06 +00:00
|
|
|
import { replaceAll } from './strings'
|
2018-11-20 08:01:23 +00:00
|
|
|
import { replaceEmoji } from './replaceEmoji'
|
2018-04-14 22:50:06 +00:00
|
|
|
|
|
|
|
export function emojifyText (text, emojis, autoplayGifs) {
|
2018-11-20 08:01:23 +00: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 01:03:26 +00:00
|
|
|
if (emojis) {
|
2018-04-14 22:50:06 +00:00
|
|
|
for (let emoji of emojis) {
|
|
|
|
let urlToUse = autoplayGifs ? emoji.url : emoji.static_url
|
|
|
|
let shortcodeWithColons = `:${emoji.shortcode}:`
|
|
|
|
text = replaceAll(
|
|
|
|
text,
|
|
|
|
shortcodeWithColons,
|
2018-08-19 22:23:40 +00:00
|
|
|
`<img class="inline-custom-emoji" draggable="false" src="${urlToUse}"
|
2018-04-14 22:50:06 +00:00
|
|
|
alt="${shortcodeWithColons}" title="${shortcodeWithColons}" />`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2018-11-20 08:01:23 +00:00
|
|
|
|
2018-04-14 22:50:06 +00:00
|
|
|
return text
|
|
|
|
}
|