fix: emoji replacement
This commit is contained in:
parent
c19dd3ee0f
commit
dc94d707b0
7 changed files with 40 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -24,6 +24,9 @@ export const Emoji = Node.create({
|
|||
native: {
|
||||
default: null,
|
||||
},
|
||||
fallback: {
|
||||
default: null,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -38,6 +41,7 @@ export const Emoji = Node.create({
|
|||
type: this.name,
|
||||
attrs: {
|
||||
native: name,
|
||||
fallback: name,
|
||||
},
|
||||
})
|
||||
},
|
||||
|
@ -51,7 +55,10 @@ export const Emoji = Node.create({
|
|||
type: this.type,
|
||||
getAttributes: (match) => {
|
||||
const [native] = match
|
||||
return { native }
|
||||
return {
|
||||
native,
|
||||
fallback: native,
|
||||
}
|
||||
},
|
||||
}),
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue