Fix emoji in markdown code blocks

Emoji in code blocks were missing from both the rendered code and the
copied text. twemoji replaces them with images, but highlighting and the
copy button work from the block's text content, which leaves images out.
We now turn the images back into text first.
This commit is contained in:
Guillaume
2026-10-19 15:42:13 +02:00
committed by Rūdolfs Ošiņš
parent 44c4c37fc7
commit 783fa6be64
5 changed files with 106 additions and 0 deletions
+2
View File
@@ -35,6 +35,7 @@
import {
isUrl,
twemoji,
untwemoji,
scrollIntoView,
canonicalize,
canonicalizeGithubImageUrl,
@@ -248,6 +249,7 @@
for (const node of nodes) {
const preElement = node.parentElement as HTMLElement;
const copyButton = document.createElement("radicle-clipboard");
untwemoji(node);
copyButton.setAttribute("text", node.textContent || "");
// Create a wrapper around the pre element,
// so we can position the copy button that works even when scrolling horizontally.
+6
View File
@@ -315,6 +315,12 @@ export function twemoji(
});
}
export function untwemoji(node: Element) {
for (const img of node.querySelectorAll("img.txt-emoji")) {
img.replaceWith(img.getAttribute("alt") ?? "");
}
}
// Formats COBs Object Ids
export function formatObjectId(id: string): string {
return id.substring(0, 7);