1 Commits
Author SHA1 Message Date
lashman 39eaf409b8 fixed div spacing and text node handling in docx export 2026-03-23 11:54:56 +02:00
+11 -2
View File
@@ -1104,6 +1104,15 @@ export const generateDocxDocument = async (
};
const processNode = (node: Node): (Paragraph | Table)[] => {
// Handle text nodes - create paragraphs so content isn't silently dropped
if (node.nodeType === Node.TEXT_NODE) {
const text = node.textContent?.trim();
if (!text) return [];
return [new Paragraph({
children: [new TextRun({ text, font: body.font, size: pt(body.size), color: formatColor(resolveColorToHex(body.color)) })],
spacing: { after: 0, line: Math.round((elements?.p?.spacing?.line || body.spacing?.line || 1.2) * 240) }
})];
}
if (node.nodeType !== Node.ELEMENT_NODE) return [];
const el = node as HTMLElement;
@@ -1481,7 +1490,7 @@ export const generateDocxDocument = async (
results.push(new Paragraph({
children: runs,
alignment: divAlign ? mapAlignment(divAlign === 'justify' ? 'both' : divAlign) : mapAlignment(body.align),
spacing: { before: 0, after: (divSpacing?.after || body.size) * 20, line: Math.round((divSpacing?.line || 1.2) * 240) }
spacing: { before: 0, after: (divSpacing?.after || 0) * 20, line: Math.round((divSpacing?.line || 1.2) * 240) }
}));
}
}
@@ -1509,7 +1518,7 @@ export const generateDocxDocument = async (
results.push(new Paragraph({
children: runs,
alignment: isImgOnly ? AlignmentType.CENTER : (divAlign ? mapAlignment(divAlign === 'justify' ? 'both' : divAlign) : mapAlignment(body.align)),
spacing: { before: 0, after: (divSpacing?.after || body.size) * 20, line: Math.round((divSpacing?.line || 1.2) * 240) }
spacing: { before: 0, after: (divSpacing?.after || 0) * 20, line: Math.round((divSpacing?.line || 1.2) * 240) }
}));
return results;
}