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
This commit is contained in:
dwindown
2025-11-15 20:05:50 +07:00
parent 550b3b69ef
commit 4471cd600f
45 changed files with 9194 additions and 508 deletions

View File

@@ -1,14 +1,22 @@
<?php
/**
* Default Email Templates
* Default Email Templates (DEPRECATED)
*
* Provides default email content for all notification events
* @deprecated Use WooNooW\Email\DefaultTemplates instead
*
* This file is kept for backwards compatibility only.
* The new source of truth is /includes/Email/DefaultTemplates.php
* which contains clean markdown templates without HTML tags.
*
* TemplateProvider now uses the new Email\DefaultTemplates directly.
*
* @package WooNooW
*/
namespace WooNooW\Core\Notifications;
use WooNooW\Email\DefaultTemplates as NewDefaultTemplates;
class DefaultEmailTemplates {
/**
@@ -19,25 +27,29 @@ class DefaultEmailTemplates {
* @return array ['subject' => string, 'body' => string]
*/
public static function get_template($event_id, $recipient_type) {
$templates = self::get_all_templates();
// Get templates directly from this class
$allTemplates = self::get_all_templates();
if (isset($templates[$event_id][$recipient_type])) {
return $templates[$event_id][$recipient_type];
// Check if event exists for this recipient type
if (isset($allTemplates[$event_id][$recipient_type])) {
return $allTemplates[$event_id][$recipient_type];
}
// Fallback
return [
'subject' => __('Notification from {store_name}', 'woonoow'),
'body' => '[card type="default"]<p>' . __('You have a new notification.', 'woonoow') . '</p>[/card]',
'body' => '[card]' . __('You have a new notification.', 'woonoow') . '[/card]',
];
}
/**
* Get all default templates
* Get all default templates (legacy method - kept for backwards compatibility)
*
* @return array
*/
private static function get_all_templates() {
// This method is now deprecated but kept for backwards compatibility
// Use WooNooW\Email\DefaultTemplates instead
return [
// ORDER EVENTS
'order_placed' => [
@@ -68,7 +80,7 @@ class DefaultEmailTemplates {
{order_items_list}
[/card]
[button link="{order_url}" style="solid"]' . __('View Order Details', 'woonoow') . '[/button]',
[button url="{order_url}" style="solid"]' . __('View Order Details', 'woonoow') . '[/button]',
],
],
@@ -97,7 +109,7 @@ class DefaultEmailTemplates {
{order_items_list}
[/card]
[button link="{order_url}" style="solid"]' . __('Track Your Order', 'woonoow') . '[/button]',
[button url="{order_url}" style="solid"]' . __('Track Your Order', 'woonoow') . '[/button]',
],
],
@@ -122,8 +134,8 @@ class DefaultEmailTemplates {
<p>' . __('If you have any questions or concerns about your order, please don\'t hesitate to contact us.', 'woonoow') . '</p>
[/card]
[button link="{order_url}" style="solid"]' . __('View Order', 'woonoow') . '[/button]
[button link="{store_url}" style="outline"]' . __('Continue Shopping', 'woonoow') . '[/button]',
[button url="{order_url}" style="solid"]' . __('View Order', 'woonoow') . '[/button]
[button url="{store_url}" style="outline"]' . __('Continue Shopping', 'woonoow') . '[/button]',
],
],
@@ -143,7 +155,7 @@ class DefaultEmailTemplates {
<p><strong>' . __('Cancelled Date:', 'woonoow') . '</strong> {order_date}</p>
[/card]
[button link="{order_url}" style="solid"]' . __('View Order Details', 'woonoow') . '[/button]',
[button url="{order_url}" style="solid"]' . __('View Order Details', 'woonoow') . '[/button]',
],
],
@@ -168,7 +180,7 @@ class DefaultEmailTemplates {
<p>' . __('If you have any questions, please contact us.', 'woonoow') . '</p>
[/card]
[button link="{order_url}" style="solid"]' . __('View Order', 'woonoow') . '[/button]',
[button url="{order_url}" style="solid"]' . __('View Order', 'woonoow') . '[/button]',
],
],
@@ -194,7 +206,7 @@ class DefaultEmailTemplates {
<p>' . __('Please restock this product to avoid running out of inventory.', 'woonoow') . '</p>
[/card]
[button link="{product_url}" style="solid"]' . __('View Product', 'woonoow') . '[/button]',
[button url="{product_url}" style="solid"]' . __('View Product', 'woonoow') . '[/button]',
],
],
@@ -218,7 +230,7 @@ class DefaultEmailTemplates {
<p>' . __('This product is no longer available for purchase. Please restock as soon as possible.', 'woonoow') . '</p>
[/card]
[button link="{product_url}" style="solid"]' . __('Manage Product', 'woonoow') . '[/button]',
[button url="{product_url}" style="solid"]' . __('Manage Product', 'woonoow') . '[/button]',
],
],
@@ -248,8 +260,8 @@ class DefaultEmailTemplates {
</ul>
[/card]
[button link="{account_url}" style="solid"]' . __('Go to My Account', 'woonoow') . '[/button]
[button link="{store_url}" style="outline"]' . __('Start Shopping', 'woonoow') . '[/button]',
[button url="{account_url}" style="solid"]' . __('Go to My Account', 'woonoow') . '[/button]
[button url="{store_url}" style="outline"]' . __('Start Shopping', 'woonoow') . '[/button]',
],
],
@@ -272,9 +284,29 @@ class DefaultEmailTemplates {
<p>{customer_note}</p>
[/card]
[button link="{order_url}" style="solid"]' . __('View Order', 'woonoow') . '[/button]',
[button url="{order_url}" style="solid"]' . __('View Order', 'woonoow') . '[/button]',
],
],
];
}
/**
* Get all new templates (direct access to new class)
*
* @return array
*/
public static function get_new_templates() {
return NewDefaultTemplates::get_all_templates();
}
/**
* Get default subject from new templates
*
* @param string $recipient_type 'staff' or 'customer'
* @param string $event_id Event ID
* @return string
*/
public static function get_default_subject($recipient_type, $event_id) {
return NewDefaultTemplates::get_default_subject($recipient_type, $event_id);
}
}