Preserve QWord paragraph spacing in DOCX

This commit is contained in:
Курнат Андрей
2026-06-02 08:03:03 +03:00
parent f5ab0448c7
commit f15467b8a1
4 changed files with 118 additions and 8 deletions
+24
View File
@@ -465,6 +465,18 @@ describe("wordOffice helpers", () => {
]);
});
it("сохраняет HTML-интервалы абзацев и заголовков для DOCX", () => {
const blocks = htmlToWordBlocks(`
<h2 style="margin-top: 6pt; margin-bottom: 10pt;">Title spacing</h2>
<p style="margin-top: 12pt; margin-bottom: 18pt;">Paragraph spacing</p>
`);
expect(blocks).toEqual([
{ type: "heading", level: 2, text: "Title spacing", runs: [{ text: "Title spacing" }], spacing: { before: 120, after: 200 } },
{ type: "paragraph", text: "Paragraph spacing", runs: [{ text: "Paragraph spacing" }], spacing: { before: 240, after: 360 } }
]);
});
it("записывает отступы абзацев в w:ind экспортированного DOCX", async () => {
const blob = await exportDocxBlob(
"Indent.docx",
@@ -477,6 +489,18 @@ describe("wordOffice helpers", () => {
expect(documentXml).toMatch(/<w:ind\b(?=[^>]*w:left="720")(?=[^>]*w:hanging="240")[^>]*\/>/);
});
it("записывает интервалы абзацев в w:spacing экспортированного DOCX", async () => {
const blob = await exportDocxBlob(
"Spacing.docx",
'<h2 style="margin-top: 6pt; margin-bottom: 10pt;">Title spacing</h2><p style="margin-top: 12pt; margin-bottom: 18pt;">Paragraph spacing</p>'
);
const zip = await JSZip.loadAsync(await blob.arrayBuffer());
const documentXml = await zip.file("word/document.xml")?.async("string");
expect(documentXml).toMatch(/<w:spacing\b(?=[^>]*w:before="120")(?=[^>]*w:after="200")[^>]*\/>/);
expect(documentXml).toMatch(/<w:spacing\b(?=[^>]*w:before="240")(?=[^>]*w:after="360")[^>]*\/>/);
});
it("нормализует HTML после импорта DOCX", () => {
expect(normalizeImportedDocxHtml(" <p>Готово</p>\n")).toBe("<p>Готово</p>");
});