StatusContent: fix custom emoji parsing

fix-error-messages
Alex Gleason 2024-11-17 23:34:34 -06:00
rodzic f335249104
commit 36e27eb592
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 16 dodań i 8 usunięć

Wyświetl plik

@ -92,17 +92,25 @@ const StatusContent: React.FC<IStatusContent> = ({
} }
if (domNode instanceof DOMText) { if (domNode instanceof DOMText) {
const parts = domNode.data.split(' ').map((part) => { const parts: Array<string | JSX.Element> = [];
const match = part.match(/^:(\w+):$/);
if (!match) return part;
const [, shortcode] = match; const textNodes = domNode.data.split(/:\w+:/);
const customEmoji = customEmojis.find((e) => e.shortcode === shortcode); const shortcodes = [...domNode.data.matchAll(/:(\w+):/g)];
if (!customEmoji) return part; for (let i = 0; i < textNodes.length; i++) {
parts.push(textNodes[i]);
return <img key={part} src={customEmoji.url} alt={part} className='inline-block h-[1em]' />; if (shortcodes[i]) {
}); const [text, shortcode] = shortcodes[i];
const customEmoji = customEmojis.find((e) => e.shortcode === shortcode);
if (customEmoji) {
parts.push(<img key={i} src={customEmoji.url} alt={shortcode} className='inline-block h-[1em]' />);
} else {
parts.push(text);
}
}
}
return <>{parts}</>; return <>{parts}</>;
} }