✅ New cleaner syntax implemented: - [card:type] instead of [card type='type'] - [button:style](url)Text[/button] instead of [button url='...' style='...'] - Standard markdown images:  ✅ Variable protection from markdown parsing: - Variables with underscores (e.g., {order_items_table}) now protected - HTML comment placeholders prevent italic/bold parsing - All variables render correctly in preview ✅ Button rendering fixes: - Buttons work in Visual mode inside cards - Buttons work in Preview mode - Button clicks prevented in visual editor - Proper styling for solid and outline buttons ✅ Backward compatibility: - Old syntax still supported - No breaking changes ✅ Bug fixes: - Fixed order_item_table → order_items_table naming - Fixed button regex to match across newlines - Added button/image parsing to parseMarkdownBasics - Prevented button clicks on .button and .button-outline classes 📚 Documentation: - NEW_MARKDOWN_SYNTAX.md - Complete user guide - MARKDOWN_SYNTAX_AND_VARIABLES.md - Technical analysis
5.8 KiB
5.8 KiB
Improvements Completed
✅ 1. Single Source of Truth with Filter Hooks
EventRegistry.php
Created centralized event registry with filter hook:
$events = EventRegistry::get_all_events();
// Filter: woonoow_notification_events_registry
DefaultTemplates.php
Added filter hooks for templates and subjects:
// Filter: woonoow_email_default_templates
$templates = apply_filters('woonoow_email_default_templates', $templates);
// Filter: woonoow_email_default_subject
$subject = apply_filters('woonoow_email_default_subject', $subject, $recipient, $event);
Usage Example
// Add custom event
add_filter('woonoow_notification_events_registry', function($events) {
$events['custom_event'] = [
'id' => 'custom_event',
'label' => 'Custom Event',
'category' => 'custom',
'recipient_type' => 'customer',
'enabled' => true,
];
return $events;
});
// Add template for custom event
add_filter('woonoow_email_default_templates', function($templates) {
$templates['customer']['custom_event'] = '[card]Custom content[/card]';
return $templates;
});
Result:
- ✅ One place to manage events
- ✅ No hardcoding
- ✅ Fully extensible
- ✅ Events and templates always aligned
✅ 2. Card Type Selector in Markdown Toolbar
Added Features
- Card Insert Button with dialog
- Card Type Selector dropdown with 6 types:
- Default - Standard white card
- Hero - Large header with gradient
- Success - Green success message
- Warning - Yellow warning message
- Info - Blue information card
- Basic - Minimal styling
Implementation
markdown-toolbar.tsx- Added dialog with card type selection- Inserts properly formatted
[card type="..."]...[/card]template - Includes placeholder content with heading
Result:
- ✅ Easy card insertion
- ✅ Visual card type selection
- ✅ Better UX for markdown editing
✅ 3. Markdown ↔ HTML Conversion for Visual Editor
Problem
Visual editor (RichTextEditor) was receiving markdown content directly, showing **bold** and ## headings as plain text.
Solution
A. Markdown → HTML (When Opening Editor)
// EmailBuilder.tsx
const htmlContent = parseMarkdownBasics(block.content);
setEditingContent(htmlContent);
B. HTML → Markdown (When Saving)
// EmailBuilder.tsx
const markdownContent = htmlToMarkdown(editingContent);
return { ...block, content: markdownContent, cardType: editingCardType };
C. New Utility: html-to-markdown.ts
Converts rich text editor HTML output back to clean markdown:
<h2>→##<strong>→**...**<em>→*...*<p>→ double newlines- Lists, links, etc.
Result:
- ✅ Visual editor shows properly formatted content
- ✅ Bold, headings, lists render correctly
- ✅ Seamless conversion between markdown and HTML
- ✅ No markdown syntax visible in visual mode
⚠️ 4. Newline Rendering in Preview
Current State
The preview already uses markdownToHtml() which includes parseMarkdownBasics():
- Single newlines →
<br>tags - Double newlines → separate
<p>tags - Lists, headings, etc. properly converted
Implementation
// EditTemplate.tsx - Line 202
const htmlContent = markdownToHtml(cardContent.trim());
The parseMarkdownBasics() function:
- Wraps text in
<p>tags - Adds
<br>for line continuations - Handles lists, headings, bold, italic, links
Status: Should be working correctly. If newlines still don't render:
- Check if markdown has proper double newlines for paragraphs
- Verify CSS doesn't have
white-space: nowrap - Test with actual template content
Files Modified
Backend (PHP)
/includes/Core/Notifications/EventRegistry.php- NEW - Single source of truth/includes/Email/DefaultTemplates.php- Added filter hooks/includes/Api/NotificationsController.php- Use EventRegistry/includes/Core/Notifications/TemplateProvider.php- Use EventRegistry
Frontend (TypeScript/React)
/admin-spa/src/components/ui/markdown-toolbar.tsx- Card type selector dialog/admin-spa/src/components/EmailBuilder/EmailBuilder.tsx- Markdown ↔ HTML conversion/admin-spa/src/lib/html-to-markdown.ts- NEW - HTML to markdown converter/admin-spa/src/lib/markdown-utils.ts- ExportparseMarkdownBasics
Testing Checklist
- Filter hooks work for adding custom events
- Filter hooks work for adding custom templates
- Card type selector opens and inserts cards
- Visual editor shows HTML (not markdown)
- Markdown editor shows markdown (not HTML)
- Switching between Visual ↔ Markdown preserves content
- Preview renders newlines correctly
- Bold, headings, lists render in preview
- No markdown syntax visible in preview
Next Steps (If Needed)
- Test newline rendering - Create a template with multiple paragraphs and verify preview
- Backend markdown processing - Ensure WordPress shortcode handler converts markdown to HTML
- CSS check - Verify email template CSS doesn't break newlines
- Variable replacement - Ensure variables work in all modes
Documentation Created
FILTER_HOOKS_GUIDE.md- Complete guide for extending events and templatesSINGLE_SOURCE_OF_TRUTH.md- Architecture documentationIMPROVEMENTS_COMPLETED.md- This file
Summary
✅ Completed:
- Single source of truth with EventRegistry
- Full filter hook system for extensibility
- Card type selector in markdown toolbar
- Proper markdown ↔ HTML conversion for visual editor
- HTML to markdown converter
⚠️ Needs Verification:
- Newline rendering in preview (likely working, needs testing)
🎯 Result: A fully functional, extensible notification system with seamless editing experience across markdown, visual, and preview modes.