Preserve QPowerPoint manual line breaks

This commit is contained in:
Курнат Андрей
2026-06-01 12:21:28 +03:00
parent 3098e4367f
commit addfcd224d
3 changed files with 157 additions and 4 deletions
+28
View File
@@ -151,6 +151,28 @@ describe("powerPointOffice helpers", () => {
expect(imported.slides[0].subtitle).toBe("Plan\nBuild\nShip");
});
it("сохраняет ручные переносы строк a:br внутри абзаца PPTX при импорте", async () => {
const zip = new JSZip();
zip.file(
"ppt/presentation.xml",
`<p:presentation xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><p:sldIdLst><p:sldId id="256" r:id="rId1"/></p:sldIdLst></p:presentation>`
);
zip.file(
"ppt/_rels/presentation.xml.rels",
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide1.xml"/></Relationships>`
);
zip.file("ppt/slides/slide1.xml", slideXmlWithManualBreakSubtitle("Roadmap", ["Plan", "Build", "Ship"]));
const blob = await zip.generateAsync({
type: "blob",
mimeType: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
});
const imported = await importPptxFile(new File([blob], "Roadmap.pptx", { type: blob.type }));
expect(imported.slides[0].title).toBe("Roadmap");
expect(imported.slides[0].subtitle).toBe("Plan\nBuild\nShip");
});
it("импортирует изображения слайда из PPTX media relationships", async () => {
const zip = new JSZip();
zip.file(
@@ -368,6 +390,12 @@ function slideXmlWithMultilineSubtitle(title: string, subtitleParagraphs: string
.join("")}</p:txBody></p:sp></p:spTree></p:cSld></p:sld>`;
}
function slideXmlWithManualBreakSubtitle(title: string, subtitleLines: string[]) {
return `<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><p:cSld><p:spTree><p:sp><p:txBody><a:p><a:r><a:t>${title}</a:t></a:r></a:p></p:txBody></p:sp><p:sp><p:txBody><a:p>${subtitleLines
.map((text, index) => `${index > 0 ? "<a:br/>" : ""}<a:r><a:t>${text}</a:t></a:r>`)
.join("")}</a:p></p:txBody></p:sp></p:spTree></p:cSld></p:sld>`;
}
function slideXmlWithPicture(title: string) {
return `<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><p:cSld><p:spTree><p:sp><p:txBody><a:p><a:r><a:t>${title}</a:t></a:r></a:p></p:txBody></p:sp><p:pic><p:nvPicPr><p:cNvPr id="4" name="Picture 1" descr="Логотип"/></p:nvPicPr><p:blipFill><a:blip r:embed="rIdImage"/></p:blipFill><p:spPr><a:xfrm><a:off x="914400" y="1828800"/><a:ext cx="2743200" cy="1371600"/></a:xfrm></p:spPr></p:pic></p:spTree></p:cSld></p:sld>`;
}