export function MarkdownToWhatsApp(text: string): string { if (!text) { return ''; } return ( text // Triple-backtick blocks → WhatsApp monospace blocks (same syntax) .replace(/```([\s\S]*?)```/g, '```$1```') // Italic **first**, but only single‐star or single‐underscore // (? `_${a || b}_`, ) // Bold: **bold** → *bold* .replace(/\*\*(.*?)\*\*/g, '*$1*') // Strikethrough: ~~strike~~ → ~strike~ .replace(/~~(.*?)~~/g, '~$1~') // Links: [text](url) → text (url) .replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, '$1 ($2)') // Lists: -, +, * → * item .replace(/^[-+*] (.*)/gm, '* $1') ); } export function WhatsappToMarkdown(text: string): string { if (!text) { return ''; } return ( text // Bold: *bold* → **bold** .replace(/\*(.*?)\*/g, '**$1**') // Strikethrough: ~strike~ → ~~strike~~ .replace(/~(.*?)~/g, '~~$1~~') // Italic: _italic_ → *italic* .replace(/_(.*?)_/g, '*$1*') ); }