From e72b86336217299ba0a8ca602bd1832f477769fc Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Tue, 30 Jun 2026 13:57:29 +0530 Subject: [PATCH] fix(word): strip HTML style blocks and alignment divs from DOCX input Pre-process markdown before Word/DOCX export to remove raw HTML artifacts ( + +# Heading +`; + const output = WordTemplateExporter.preprocessMarkdownForWordExport(input); + expect(output).not.toContain(''); + expect(output).not.toContain('sneh-a4-print'); + expect(output).not.toContain('@media print'); + expect(output).toContain('# Heading'); + }); + + test('removes HTML comments outside style blocks', () => { + const input = ` +Hello world +`; + const output = WordTemplateExporter.preprocessMarkdownForWordExport(input); + expect(output).not.toContain(''); + expect(output).toContain('Hello world'); + }); + + test('removes alignment div tags', () => { + const input = `
+Centered content +
+`; + const output = WordTemplateExporter.preprocessMarkdownForWordExport(input); + expect(output).not.toContain('
'); + expect(output).not.toContain('
'); + expect(output).toContain('Centered content'); + }); + + test('preserves regular markdown content', () => { + const input = `# Title + +| A | B | +|---|---| +| 1 | 2 | +`; + const output = WordTemplateExporter.preprocessMarkdownForWordExport(input); + expect(output).toBe(input); + }); + + test('handles content with no HTML artifacts', () => { + const input = 'Plain text paragraph.'; + const output = WordTemplateExporter.preprocessMarkdownForWordExport(input); + expect(output).toBe(input); + }); +});