Files
WooNooW/IMPROVEMENTS_COMPLETED.md
dwindown 4471cd600f feat: Complete markdown syntax refinement and variable protection
 New cleaner syntax implemented:
- [card:type] instead of [card type='type']
- [button:style](url)Text[/button] instead of [button url='...' style='...']
- Standard markdown images: ![alt](url)

 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
2025-11-15 20:05:50 +07:00

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:

  1. Check if markdown has proper double newlines for paragraphs
  2. Verify CSS doesn't have white-space: nowrap
  3. Test with actual template content

Files Modified

Backend (PHP)

  1. /includes/Core/Notifications/EventRegistry.php - NEW - Single source of truth
  2. /includes/Email/DefaultTemplates.php - Added filter hooks
  3. /includes/Api/NotificationsController.php - Use EventRegistry
  4. /includes/Core/Notifications/TemplateProvider.php - Use EventRegistry

Frontend (TypeScript/React)

  1. /admin-spa/src/components/ui/markdown-toolbar.tsx - Card type selector dialog
  2. /admin-spa/src/components/EmailBuilder/EmailBuilder.tsx - Markdown ↔ HTML conversion
  3. /admin-spa/src/lib/html-to-markdown.ts - NEW - HTML to markdown converter
  4. /admin-spa/src/lib/markdown-utils.ts - Export parseMarkdownBasics

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)

  1. Test newline rendering - Create a template with multiple paragraphs and verify preview
  2. Backend markdown processing - Ensure WordPress shortcode handler converts markdown to HTML
  3. CSS check - Verify email template CSS doesn't break newlines
  4. Variable replacement - Ensure variables work in all modes

Documentation Created

  1. FILTER_HOOKS_GUIDE.md - Complete guide for extending events and templates
  2. SINGLE_SOURCE_OF_TRUTH.md - Architecture documentation
  3. IMPROVEMENTS_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.