1// Uploaded media keeps the extension the server sniffed it into, so the url
2// tells the markdown renderer whether image syntax should become a player.
3export function isVideo(url: string) {
4 return /\.(mp4|webm)(?:[?#]|$)/i.test(url);
5}
6
7// hasMedia reports whether body contains an attachment: images and video share
8// the markdown image syntax.
9export function hasMedia(body: string) {
10 return /!\[[^\]]*\]\([^)]+\)/.test(body);
11}
12
13// attachmentNames lists the alt text of each attachment in body.
14export function attachmentNames(body: string) {
15 return [...body.matchAll(/!\[([^\]]*)\]\([^)]+\)/g)].map((m) => m[1] || "attachment");
16}