Respect text-only emoji setting after svgification

Follow-up to #271. Skip svgifyEmoji when body.text-emojis is set so
deEmojify can strip Unicode from replies; also unwrap existing .emoji
spans from messages rendered before the setting was applied.

Related to #270
This commit is contained in:
sunnyegg
2026-06-01 13:41:27 +07:00
committed by GitHub
parent 8f93d44917
commit ca6907239c
2 changed files with 18 additions and 4 deletions

View File

@@ -233,8 +233,13 @@ function _svgifyText(text) {
}
return out;
}
/** When "Text-only Emojis" is on, keep Unicode in HTML so deEmojify() can strip them. */
function _useSvgEmoji() {
return typeof document === 'undefined' || !document.body?.classList.contains('text-emojis');
}
export function svgifyEmoji(html) {
if (!html || !_EMOJI_RE.test(html)) return html;
if (!_useSvgEmoji() || !html || !_EMOJI_RE.test(html)) return html;
const parts = html.split(/(<[^>]*>)/); // odd indices = tags
let codeDepth = 0;
for (let i = 0; i < parts.length; i++) {
@@ -282,7 +287,7 @@ export function processWithThinking(text) {
html += mdToHtml(content);
}
return svgifyEmoji(html);
return _useSvgEmoji() ? svgifyEmoji(html) : html;
}
/**
@@ -539,7 +544,7 @@ export function mdToHtml(src) {
s = s.replace(`___CODE_BLOCK_${index}___`, block);
});
return svgifyEmoji(s);
return _useSvgEmoji() ? svgifyEmoji(s) : s;
}
/**