mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 10:10:30 +08:00
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:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user