✅ 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
9.8 KiB
9.8 KiB
✅ Markdown Mode - Modern 2025 Approach! 🚀
IMPLEMENTED! User-Friendly Markdown with HTML Pivot
The Architecture
User-Facing: Markdown & Visual
Behind the Scenes: HTML Pivot
┌─────────────────────────────────────────┐
│ USER INTERFACE │
├─────────────────────────────────────────┤
│ │
│ Visual Builder ←→ Markdown │
│ (Drag & drop) (Easy typing) │
│ │
└─────────────────────────────────────────┘
↕
┌───────────────────────┐
│ HTML PIVOT │
│ (Internal only) │
└───────────────────────┘
↕
┌───────────────────────┐
│ DATABASE (HTML) │
└───────────────────────┘
How It Works
Complexity on Our Side, Simplicity for Users
// User sees: Markdown or Visual
// System handles: HTML conversion
Visual Builder ←→ HTML ←→ Markdown
↓ ↓ ↓
Blocks Pivot User-friendly
Data Flow
1. Loading Template
Database (HTML)
↓
Load HTML
↓
Convert to both views:
├→ HTML → Markdown (for Markdown mode)
└→ HTML → Blocks (for Visual mode)
2. Editing in Visual Mode
User edits blocks
↓
Blocks → HTML (pivot)
↓
HTML → Markdown (sync)
↓
✅ All formats in sync!
3. Editing in Markdown Mode
User types markdown
↓
Markdown → HTML (pivot)
↓
HTML → Blocks (sync)
↓
✅ All formats in sync!
4. Switching Modes
Visual → Markdown:
Blocks → HTML → Markdown
Markdown → Visual:
Markdown → HTML → Blocks
✅ No data loss!
5. Saving
Any mode
↓
HTML (always ready)
↓
Save to database
↓
✅ Simple!
Why This Is Better
For Users:
- ✅ Markdown: Easy to type, mobile-friendly
- ✅ Visual: Drag & drop, no coding needed
- ✅ Modern: 2025 standard (like GitHub, Notion, Slack)
- ✅ Flexible: Choose your preferred mode
For Mobile:
HTML: <strong>bold</strong> ❌ Hard to type
Markdown: **bold** ✅ Easy to type!
HTML: <div class="card">...</div> ❌ Painful on phone
Markdown: [card]...[/card] ✅ Simple!
For Developers (Us):
- ✅ HTML pivot = Database compatibility
- ✅ Clean conversion logic
- ✅ All complexity hidden from users
- ✅ Easy to maintain
User Experience
What Users See:
Visual Builder:
┌─────────────────────────────┐
│ [Add Block ▼] Markdown │ ← Toggle button
├─────────────────────────────┤
│ ┌───────────────────────┐ │
│ │ 🎨 Hero Card │ │
│ │ ## Welcome! │ │
│ │ Content here... │ │
│ └───────────────────────┘ │
└─────────────────────────────┘
Markdown Mode:
┌─────────────────────────────┐
│ Visual Builder [Markdown]│ ← Toggle button
├─────────────────────────────┤
│ [card type="hero"] │
│ │
│ ## Welcome! │
│ │
│ Content here... │
│ │
│ [/card] │
└─────────────────────────────┘
💡 Write in Markdown - easy to type,
even on mobile!
Conversion Logic
Visual ↔ HTML ↔ Markdown
// Visual → HTML
blocksToHTML(blocks) → HTML
// HTML → Visual
htmlToBlocks(HTML) → blocks
// Markdown → HTML
markdownToHtml(markdown) → HTML
// HTML → Markdown
htmlToMarkdown(HTML) → markdown
Automatic Sync:
// When user edits in Visual mode
handleBlocksChange(newBlocks) {
setBlocks(newBlocks);
const html = blocksToHTML(newBlocks);
setHtmlContent(html); // Update pivot
setMarkdownContent(htmlToMarkdown(html)); // Sync markdown
}
// When user edits in Markdown mode
handleMarkdownChange(newMarkdown) {
setMarkdownContent(newMarkdown);
const html = markdownToHtml(newMarkdown);
setHtmlContent(html); // Update pivot
setBlocks(htmlToBlocks(html)); // Sync blocks
}
What Changed
Renamed:
- ❌ "Code Mode" → ✅ "Markdown"
- ❌
codeMode→ ✅markdownMode - ❌
handleCodeModeToggle→ ✅handleMarkdownModeToggle
Added:
- ✅
markdownContentstate - ✅
handleMarkdownChangehandler - ✅
htmlToMarkdown()conversion - ✅ Automatic sync between all formats
User-Facing:
- ✅ "Markdown" button (not "Code Mode")
- ✅ Markdown-friendly placeholder text
- ✅ Mobile-friendly messaging
- ✅ Clear sync indicators
Benefits Summary
| Feature | Old (HTML Code) | New (Markdown) |
|---|---|---|
| Typing | <strong>bold</strong> |
**bold** ✅ |
| Mobile | Painful ❌ | Easy ✅ |
| Learning curve | High ❌ | Low ✅ |
| Modern | Old-school ❌ | 2025 standard ✅ |
| User-friendly | No ❌ | Yes ✅ |
| Industry standard | No ❌ | Yes (GitHub, Notion) ✅ |
Markdown Syntax Supported
Basic Formatting:
**bold**
*italic*
## Heading 2
### Heading 3
Cards:
[card type="hero"]
Content here
[/card]
[card type="success"]
Success message
[/card]
[card type="basic"]
Plain text
[/card]
Buttons:
[button url="/shop"]Shop Now[/button]
Lists:
✓ Checkmark item
• Bullet item
- Dash item
Horizontal Rule:
---
Testing Checklist
✅ Visual → Markdown:
- Edit in visual mode
- Click "Markdown" button
- See markdown with all content
- Edit markdown
- Click "Visual Builder"
- All changes preserved
✅ Markdown → Visual:
- Click "Markdown"
- Type markdown
- Click "Visual Builder"
- See blocks with all content
- Edit blocks
- Click "Markdown"
- All changes preserved
✅ Save & Reload:
- Edit in any mode
- Save
- Reload page
- All changes preserved
- Can switch modes freely
✅ Mobile:
- Open on mobile
- Click "Markdown"
- Type easily on phone
- Switch to visual
- Works smoothly
Example Workflow
User Story: Edit on Mobile
- Open template on phone
- Click "Markdown" button
- Type easily:
[card type="hero"] ## Order Confirmed! Thank you **{customer_name}**! [/card] [button url="{order_url}"]View Order[/button] - Click "Preview" → See beautiful email
- Save → Done! ✅
Much easier than typing HTML on phone!
Architecture Summary
┌─────────────────────────────────────────┐
│ USER EXPERIENCE │
├─────────────────────────────────────────┤
│ Visual Builder ←→ Markdown │
│ (Easy) (Easy) │
└─────────────────────────────────────────┘
↕
┌─────────────────────────────────────────┐
│ SYSTEM COMPLEXITY │
├─────────────────────────────────────────┤
│ HTML Pivot (Internal) │
│ - Conversion logic │
│ - Format sync │
│ - Database compatibility │
└─────────────────────────────────────────┘
Complexity on our side, simplicity for users! ✅
Files Modified
EditTemplate.tsx
Changes:
- ✅ Added
markdownContentstate - ✅ Renamed
codeMode→markdownMode - ✅ Added
handleMarkdownChangehandler - ✅ Updated
handleMarkdownModeTogglefor proper conversion - ✅ Updated
handleBlocksChangeto sync markdown - ✅ Changed button text to "Markdown"
- ✅ Updated placeholder and help text
- ✅ Import
htmlToMarkdownfunction
What's Next
Test It:
- Hard refresh (Cmd+Shift+R)
- Open any template
- Click "Markdown" button
- ✅ See markdown syntax
- Edit markdown
- Click "Visual Builder"
- ✅ See your changes in blocks
- Save
- ✅ All preserved!
Try on Mobile:
- Open on phone
- Click "Markdown"
- Type easily
- ✅ Much better than HTML!
🎉 DONE! Modern, user-friendly, mobile-optimized! 🚀
Markdown for users, HTML for system - perfect balance!