export type CaptionSegment = | { type: "text"; text: string } | { type: "hashtag"; tag: string } | { type: "mention"; name: string }; export function parseCaption(caption: string): CaptionSegment[] { const segments: CaptionSegment[] = []; const parts = caption.split(/(#\w{1,50}|@\w{1,50})/g); for (const part of parts) { if (part.startsWith("#")) { segments.push({ type: "hashtag", tag: part.slice(1).toLowerCase() }); } else if (part.startsWith("@")) { segments.push({ type: "mention", name: part.slice(1) }); } else if (part) { segments.push({ type: "text", text: part }); } } return segments; }