Preserve QWord paragraph indentation in DOCX

This commit is contained in:
Курнат Андрей
2026-06-01 20:05:48 +03:00
parent 15ea571395
commit d403ea7f10
4 changed files with 157 additions and 5 deletions
+24
View File
@@ -371,6 +371,30 @@ describe("wordOffice helpers", () => {
expect(documentXml).toContain("<w:strike/>");
});
it("сохраняет HTML-отступы абзацев и заголовков для DOCX", () => {
const blocks = htmlToWordBlocks(`
<h1 style="margin-left: 36pt; text-indent: 18pt;">Title</h1>
<p style="margin-left: 48px; text-indent: -12pt;">Indented paragraph</p>
`);
expect(blocks).toEqual([
{ type: "heading", level: 1, text: "Title", runs: [{ text: "Title" }], indent: { left: 720, firstLine: 360 } },
{ type: "paragraph", text: "Indented paragraph", runs: [{ text: "Indented paragraph" }], indent: { left: 720, hanging: 240 } }
]);
});
it("записывает отступы абзацев в w:ind экспортированного DOCX", async () => {
const blob = await exportDocxBlob(
"Indent.docx",
'<p style="margin-left: 36pt; text-indent: 18pt;">Indented</p><p style="margin-left: 48px; text-indent: -12pt;">Hanging</p>'
);
const zip = await JSZip.loadAsync(await blob.arrayBuffer());
const documentXml = await zip.file("word/document.xml")?.async("string");
expect(documentXml).toMatch(/<w:ind\b(?=[^>]*w:left="720")(?=[^>]*w:firstLine="360")[^>]*\/>/);
expect(documentXml).toMatch(/<w:ind\b(?=[^>]*w:left="720")(?=[^>]*w:hanging="240")[^>]*\/>/);
});
it("нормализует HTML после импорта DOCX", () => {
expect(normalizeImportedDocxHtml(" <p>Готово</p>\n")).toBe("<p>Готово</p>");
});