fix: pasting emojis

zio/stable
patak 2023-05-08 21:10:52 +02:00
parent 9d3c7ef116
commit fc97e8ff5b
1 changed files with 4 additions and 2 deletions

View File

@ -168,6 +168,8 @@ export function recursiveTreeToText(input: Node): string {
return treeToText(input) return treeToText(input)
} }
const emojiIdNeedsWrappingRE = /^(\d|\w|-|_)$/
export function treeToText(input: Node): string { export function treeToText(input: Node): string {
let pre = '' let pre = ''
let body = '' let body = ''
@ -218,8 +220,8 @@ export function treeToText(input: Node): string {
if (input.name === 'img' || input.name === 'picture') { if (input.name === 'img' || input.name === 'picture') {
if (input.attributes.class?.includes('custom-emoji')) { if (input.attributes.class?.includes('custom-emoji')) {
const id = input.attributes['data-emoji-id'] ?? input.attributes.title ?? input.attributes.alt ?? 'unknown' const id = input.attributes['data-emoji-id'] ?? input.attributes.alt ?? input.attributes.title ?? 'unknown'
return id[0] !== ':' ? `:${id}:` : id return id.match(emojiIdNeedsWrappingRE) ? `:${id}:` : id
} }
if (input.attributes.class?.includes('iconify-emoji')) if (input.attributes.class?.includes('iconify-emoji'))
return input.attributes.alt return input.attributes.alt