fix: emoji replacement

This commit is contained in:
Anthony Fu 2022-12-27 21:42:58 +01:00
parent c19dd3ee0f
commit dc94d707b0
7 changed files with 40 additions and 4 deletions

View file

@ -2,8 +2,9 @@
import type { Emoji } from 'masto'
import type { Node } from 'ultrahtml'
import { TEXT_NODE, parse, render, walkSync } from 'ultrahtml'
import createEmojiRegex from 'emoji-regex'
export const EMOJI_REGEX = /(\p{Emoji_Presentation})/ug
export const EMOJI_REGEX = createEmojiRegex()
const decoder = process.client ? document.createElement('textarea') : null as any as HTMLTextAreaElement
export function decodeHtml(text: string) {
@ -25,7 +26,7 @@ export function parseMastodonHTML(html: string, customEmojis: Record<string, Emo
? `<img src="${emoji.url}" alt=":${name}:" class="custom-emoji" data-emoji-id="${name}" />`
: `:${name}:`
})
.replace(EMOJI_REGEX, '<em-emoji native="$1" />')
.replace(EMOJI_REGEX, '<em-emoji native="$&" fallback="$&" />')
if (markdown) {
// handle code blocks