Fix button roundtrip in editor, alignment persistence, and test email rendering
This commit is contained in:
@@ -68,8 +68,23 @@ export function htmlToMarkdown(html: string): string {
|
||||
}).join('\n') + '\n\n';
|
||||
});
|
||||
|
||||
// Paragraphs - convert to double newlines
|
||||
markdown = markdown.replace(/<p[^>]*>(.*?)<\/p>/gis, '$1\n\n');
|
||||
// Paragraphs - preserve text-align by using placeholders
|
||||
const alignedParagraphs: { [key: string]: string } = {};
|
||||
let alignIndex = 0;
|
||||
markdown = markdown.replace(/<p([^>]*)>(.*?)<\/p>/gis, (match, attrs, content) => {
|
||||
// Check for text-align in style attribute
|
||||
const alignMatch = attrs.match(/text-align:\s*(center|right)/i);
|
||||
if (alignMatch) {
|
||||
const align = alignMatch[1].toLowerCase();
|
||||
// Use double-bracket placeholder that won't be matched by HTML regex
|
||||
const placeholder = `[[ALIGN${alignIndex}]]`;
|
||||
alignedParagraphs[placeholder] = `<p style="text-align: ${align};">${content}</p>`;
|
||||
alignIndex++;
|
||||
return placeholder + '\n\n';
|
||||
}
|
||||
// No alignment, convert to plain text
|
||||
return `${content}\n\n`;
|
||||
});
|
||||
|
||||
// Line breaks
|
||||
markdown = markdown.replace(/<br\s*\/?>/gi, '\n');
|
||||
@@ -80,6 +95,11 @@ export function htmlToMarkdown(html: string): string {
|
||||
// Remove remaining HTML tags
|
||||
markdown = markdown.replace(/<[^>]+>/g, '');
|
||||
|
||||
// Restore aligned paragraphs
|
||||
Object.entries(alignedParagraphs).forEach(([placeholder, html]) => {
|
||||
markdown = markdown.replace(placeholder, html);
|
||||
});
|
||||
|
||||
// Clean up excessive newlines
|
||||
markdown = markdown.replace(/\n{3,}/g, '\n\n');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user