diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-11-14 22:43:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-14 22:43:56 +0100 |
commit | e589afa0ef520747919935956d2d87746000adc9 (patch) | |
tree | b4df6d9329686bebd09cbfcc107b8fe32c413af3 /app/javascript/flavours | |
parent | 7a8cd0cb0a61d5091071d682bfb263247a324d3a (diff) | |
parent | 8aa56aedfd5cb5a2caa4dd070fb6a233e960dbec (diff) |
Merge pull request #1929 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/javascript/flavours')
-rw-r--r-- | app/javascript/flavours/glitch/features/emoji/emoji.js | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/app/javascript/flavours/glitch/features/emoji/emoji.js b/app/javascript/flavours/glitch/features/emoji/emoji.js index 6138164e0..880f9401d 100644 --- a/app/javascript/flavours/glitch/features/emoji/emoji.js +++ b/app/javascript/flavours/glitch/features/emoji/emoji.js @@ -19,10 +19,13 @@ const emojiFilename = (filename) => { return borderedEmoji.includes(filename) ? (filename + '_border') : filename; }; +const domParser = new DOMParser(); + const emojifyTextNode = (node, customEmojis) => { - const parentElement = node.parentElement; let str = node.textContent; + const fragment = new DocumentFragment(); + for (;;) { let match, i = 0; @@ -64,12 +67,16 @@ const emojifyTextNode = (node, customEmojis) => { } } + fragment.append(document.createTextNode(str.slice(0, i))); + if (replacement) { + fragment.append(domParser.parseFromString(replacement, 'text/html').documentElement.getElementsByTagName('img')[0]); + } node.textContent = str.slice(0, i); - parentElement.insertAdjacentHTML('beforeend', replacement); str = str.slice(rend); - node = document.createTextNode(str); - parentElement.append(node); } + + fragment.append(document.createTextNode(str)); + node.parentElement.replaceChild(fragment, node); }; const emojifyNode = (node, customEmojis) => { |