# Converter Fixes Summary ## Issues Fixed ### 1. ✅ Exact Event Naming - No Mapping **Problem:** API used `order_processing` but Email templates had `order_confirmed`. Required a "bridge" mapping. **Solution:** Renamed template methods to match API exactly: - `customer_order_confirmed()` → `customer_order_processing()` - `staff_order_confirmed()` → `staff_order_processing()` - `customer_registered()` → `customer_new_customer()` **Result:** Direct 1:1 mapping, no confusion, clean code. ### 2. ✅ Markdown Converter Respects [card] Boundaries **Problem:** `markdownToBlocks()` was splitting by double newlines (`\n\n`), causing: - Raw `[/card]` tags left in output - Each line with double space became a new card - `##` headings not rendered **Root Cause:** ```typescript // OLD - WRONG const sections = markdown.split(/\n\n+/); // Splits by double newlines! ``` **Solution:** Parse by `[card]...[/card]` boundaries: ```typescript // NEW - CORRECT while (remaining.length > 0) { const cardMatch = remaining.match(/^\[card([^\]]*)\]([\s\S]*?)\[\/card\]/); if (cardMatch) { // Extract content between [card] and [/card] const content = cardMatch[2].trim(); blocks.push({ type: 'card', content }); remaining = remaining.substring(cardMatch[0].length); // Advance! } } ``` **Key Changes:** - Uses regex to find `[card]...[/card]` pairs - Extracts content between tags - Advances `remaining` string after each match - No splitting by newlines ### 3. ⚠️ Markdown Rendering in Preview (Partial) **Current State:** - Markdown is stored in database: `## Heading\n\n**bold**` - Frontend CodeEditor shows clean markdown ✅ - Preview shows markdown as-is (not converted to HTML) ❌ **Why:** The preview uses `htmlContent` which contains `[card]## Heading[/card]` but doesn't convert the markdown inside to HTML. **Next Steps:** Backend PHP needs to convert markdown to HTML when rendering emails. The `[card]` shortcode handler should: 1. Extract content 2. Convert markdown to HTML 3. Wrap in styled div ## Files Modified 1. `/includes/Email/DefaultTemplates.php` - Renamed methods to match API event IDs exactly - Updated subject keys 2. `/includes/Core/Notifications/TemplateProvider.php` - Removed event mapping - Direct lookup: `$allEmailTemplates[$recipient_type][$event_id]` 3. `/admin-spa/src/components/EmailBuilder/converter.ts` - Fixed `markdownToBlocks()` to respect `[card]...[/card]` boundaries - Added proper string advancement - No more double-newline splitting ## Testing Checklist - [x] Event names match between API and templates - [x] No mapping/bridging code - [x] Markdown editor shows clean markdown - [x] `[/card]` tags not left in output - [x] Double newlines don't create new cards - [ ] Preview renders markdown as HTML (needs backend fix) - [ ] Headings show as `

` not `##` in preview - [ ] Line breaks work correctly in preview ## Remaining Work **Backend Markdown Rendering:** The WordPress shortcode handler for `[card]` needs to convert markdown content to HTML before rendering. Location: Likely in `/includes/Email/` or `/includes/Core/Notifications/` Required: A function that processes `[card]` shortcodes and converts their markdown content to HTML using a markdown parser.