mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
[Glitch] Fix nodes order being sometimes mangled when rewriting emoji
Port ccbca50a25
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
b5698af25f
commit
8aa56aedfd
@ -19,10 +19,13 @@ const emojiFilename = (filename) => {
|
|||||||
return borderedEmoji.includes(filename) ? (filename + '_border') : filename;
|
return borderedEmoji.includes(filename) ? (filename + '_border') : filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const domParser = new DOMParser();
|
||||||
|
|
||||||
const emojifyTextNode = (node, customEmojis) => {
|
const emojifyTextNode = (node, customEmojis) => {
|
||||||
const parentElement = node.parentElement;
|
|
||||||
let str = node.textContent;
|
let str = node.textContent;
|
||||||
|
|
||||||
|
const fragment = new DocumentFragment();
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
let match, i = 0;
|
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);
|
node.textContent = str.slice(0, i);
|
||||||
parentElement.insertAdjacentHTML('beforeend', replacement);
|
|
||||||
str = str.slice(rend);
|
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) => {
|
const emojifyNode = (node, customEmojis) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user