fix: button preservation when loading card for editing - add TipTap data attrs to parseMarkdownBasics

This commit is contained in:
Dwindi Ramadhana
2026-01-01 23:41:15 +07:00
parent 2ce7c0b263
commit 0a33ba0401

View File

@@ -151,15 +151,20 @@ export function parseMarkdownBasics(text: string): string {
// Parse [button:style](url)Text[/button] (new syntax) - must come before images // Parse [button:style](url)Text[/button] (new syntax) - must come before images
// Allow whitespace and newlines between parts // Allow whitespace and newlines between parts
// Include data-button attributes for TipTap recognition
html = html.replace(/\[button:(\w+)\]\(([^)]+)\)([\s\S]*?)\[\/button\]/g, (match, style, url, text) => { html = html.replace(/\[button:(\w+)\]\(([^)]+)\)([\s\S]*?)\[\/button\]/g, (match, style, url, text) => {
const buttonClass = style === 'outline' ? 'button-outline' : 'button'; const buttonClass = style === 'outline' ? 'button-outline' : 'button';
return `<p style="text-align: center;"><a href="${url}" class="${buttonClass}">${text.trim()}</a></p>`; const trimmedText = text.trim();
return `<a href="${url}" class="${buttonClass}" data-button="" data-text="${trimmedText}" data-href="${url}" data-style="${style}">${trimmedText}</a>`;
}); });
// Parse [button url="..."] shortcodes (old syntax - backward compatibility) // Parse [button url="..."] shortcodes (old syntax - backward compatibility)
// Include data-button attributes for TipTap recognition
html = html.replace(/\[button\s+url="([^"]+)"(?:\s+style="([^"]+)")?\]([^\[]+)\[\/button\]/g, (match, url, style, text) => { html = html.replace(/\[button\s+url="([^"]+)"(?:\s+style="([^"]+)")?\]([^\[]+)\[\/button\]/g, (match, url, style, text) => {
const buttonClass = style === 'outline' ? 'button-outline' : 'button'; const buttonStyle = style || 'solid';
return `<p style="text-align: center;"><a href="${url}" class="${buttonClass}">${text.trim()}</a></p>`; const buttonClass = buttonStyle === 'outline' ? 'button-outline' : 'button';
const trimmedText = text.trim();
return `<a href="${url}" class="${buttonClass}" data-button="" data-text="${trimmedText}" data-href="${url}" data-style="${buttonStyle}">${trimmedText}</a>`;
}); });
// Images (must come before links) // Images (must come before links)