From fc97e8ff5b5ad077417a32440a978e49b8449cc0 Mon Sep 17 00:00:00 2001 From: patak Date: Mon, 8 May 2023 21:10:52 +0200 Subject: [PATCH] fix: pasting emojis --- composables/content-parse.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/composables/content-parse.ts b/composables/content-parse.ts index 0ae674f1..a055af50 100644 --- a/composables/content-parse.ts +++ b/composables/content-parse.ts @@ -168,6 +168,8 @@ export function recursiveTreeToText(input: Node): string { return treeToText(input) } +const emojiIdNeedsWrappingRE = /^(\d|\w|-|_)$/ + export function treeToText(input: Node): string { let pre = '' let body = '' @@ -218,8 +220,8 @@ export function treeToText(input: Node): string { if (input.name === 'img' || input.name === 'picture') { if (input.attributes.class?.includes('custom-emoji')) { - const id = input.attributes['data-emoji-id'] ?? input.attributes.title ?? input.attributes.alt ?? 'unknown' - return id[0] !== ':' ? `:${id}:` : id + const id = input.attributes['data-emoji-id'] ?? input.attributes.alt ?? input.attributes.title ?? 'unknown' + return id.match(emojiIdNeedsWrappingRE) ? `:${id}:` : id } if (input.attributes.class?.includes('iconify-emoji')) return input.attributes.alt