export function parseAndWrapCaptions(caption) { return caption.replace(/\[([^\]]+)\]\((https?:\/\/[^\)]+)\)/g, (match,text, content) => { // Split the content by spaces to identify potential URLs const parts = content.split(' '); const url = parts.find(part => part.startsWith('https://')); if (url) { // If a URL is found, wrap the content in an anchor tag using the first URL return `${text}`; } else { // If no URL, join the parts with a comma return content.split(' ').join(', '); } }); }