Radish alpha
r
rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5
Radicle web interface
Radicle
Git
Fix twemojis display
Sebastian Martinez committed 1 year ago
commit b3be042b5193adc60e22186c27a3f0d8fd61f069
parent 846daf0
3 files changed +15 -3
modified src/components/Markdown.svelte
@@ -137,6 +137,7 @@
    // pointing at the repos /raw endpoint.
    for (const i of container.querySelectorAll("img")) {
      const imagePath = i.getAttribute("src");
+
      const imageClass = i.getAttribute("class");

      // If the image is an oid embed
      if (imagePath && isCommit(imagePath)) {
@@ -160,7 +161,8 @@
      }

      // Make sure the source isn't a URL before trying to fetch it from the repo
-
      if (imagePath && !isUrl(imagePath) && !imagePath.startsWith("/twemoji")) {
+
      const emoji = imageClass && imageClass === "txt-emoji";
+
      if (imagePath && !isUrl(imagePath) && !emoji) {
        i.setAttribute("src", `${rawPath}/${canonicalize(imagePath, path)}`);
      }
    }
@@ -349,6 +351,10 @@
    max-width: 100%;
  }

+
  .markdown :global(img.txt-emoji) {
+
    height: 1rem;
+
  }
+

  .markdown :global(code) {
    font-family: var(--font-family-monospace);
    font-size: var(--font-size-small);
modified src/lib/markdown.ts
@@ -89,7 +89,13 @@ export const markdownWithExtensions = new Marked(
  katexMarkedExtension({ throwOnError: false }),
  markedLinkifyIt({}, { fuzzyLink: false }),
  markedFootnote({ refMarkers: true }),
-
  markedEmoji({ emojis }),
+
  markedEmoji({
+
    emojis,
+
    renderer: (token: { name: string; emoji: string }) => {
+
      const src = token.emoji.codePointAt(0)?.toString(16);
+
      return `<img alt="${token.name}" src="/twemoji/${src}.svg" class="txt-emoji">`;
+
    },
+
  }),
  ((): MarkedExtension => ({
    extensions: [anchorMarkedExtension],
  }))(),
modified src/lib/utils.ts
@@ -244,7 +244,7 @@ export function twemoji(
    base: "/",
    folder: "twemoji",
    ext: ".svg",
-
    className: `txt-emoji`,
+
    className: "txt-emoji",
  });
}