tutu/src/masto/toot.ts
thislight 5d6eb7282a
All checks were successful
/ depoly (push) Successful in 1m18s
use innerHTML property
2024-11-24 17:16:06 +08:00

25 lines
715 B
TypeScript

import { cache } from "@solidjs/router";
import type { mastodon } from "masto";
import { createRenderEffect, createResource, type Accessor } from "solid-js";
const CUSTOM_EMOJI_REGEX = /:(\S+):/g;
/**
* Resolve the custom emojis in string to HTML.
*/
export function resolveCustomEmoji(
content: string,
emojis: mastodon.v1.CustomEmoji[],
) {
return content.replace(CUSTOM_EMOJI_REGEX, (original, shortcode: string) => {
const emoji = emojis.find((x) => x.shortcode === shortcode);
if (!emoji) {
return original;
}
return `<img src="${emoji.url}" class="custom-emoji" alt="${shortcode}"/>`;
});
}
export function hasCustomEmoji(s: string) {
return CUSTOM_EMOJI_REGEX.test(s);
}