fix: resolve container width issues, spa redirects, and appearance settings overwrite. feat: enhance order/sub details and newsletter layout
This commit is contained in:
@@ -8,11 +8,27 @@ export function htmlToMarkdown(html: string): string {
|
||||
|
||||
let markdown = html;
|
||||
|
||||
// Headings
|
||||
markdown = markdown.replace(/<h1>(.*?)<\/h1>/gi, '# $1\n\n');
|
||||
markdown = markdown.replace(/<h2>(.*?)<\/h2>/gi, '## $1\n\n');
|
||||
markdown = markdown.replace(/<h3>(.*?)<\/h3>/gi, '### $1\n\n');
|
||||
markdown = markdown.replace(/<h4>(.*?)<\/h4>/gi, '#### $1\n\n');
|
||||
// Store aligned headings for preservation
|
||||
const alignedHeadings: { [key: string]: string } = {};
|
||||
let headingIndex = 0;
|
||||
|
||||
// Process headings with potential style attributes
|
||||
for (let level = 1; level <= 4; level++) {
|
||||
const hashes = '#'.repeat(level);
|
||||
markdown = markdown.replace(new RegExp(`<h${level}([^>]*)>(.*?)</h${level}>`, '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();
|
||||
const placeholder = `[[HEADING${headingIndex}]]`;
|
||||
alignedHeadings[placeholder] = `<h${level} style="text-align: ${align};">${content}</h${level}>`;
|
||||
headingIndex++;
|
||||
return placeholder + '\n\n';
|
||||
}
|
||||
// No alignment, convert to markdown
|
||||
return `${hashes} ${content}\n\n`;
|
||||
});
|
||||
}
|
||||
|
||||
// Bold
|
||||
markdown = markdown.replace(/<strong>(.*?)<\/strong>/gi, '**$1**');
|
||||
@@ -100,6 +116,11 @@ export function htmlToMarkdown(html: string): string {
|
||||
markdown = markdown.replace(placeholder, html);
|
||||
});
|
||||
|
||||
// Restore aligned headings
|
||||
Object.entries(alignedHeadings).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