Preserve QPowerPoint subtitle lists in PPTX

This commit is contained in:
Курнат Андрей
2026-06-02 05:34:40 +03:00
parent 464484bb19
commit 57cce9ea96
6 changed files with 220 additions and 8 deletions
+88
View File
@@ -173,6 +173,86 @@ describe("powerPointOffice helpers", () => {
expect(imported.slides[0].subtitle).toBe("Plan\nBuild\nShip");
});
it("импортирует маркированные и нумерованные списки подзаголовка PPTX", async () => {
const bulletZip = new JSZip();
bulletZip.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>`
);
bulletZip.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>`
);
bulletZip.file("ppt/slides/slide1.xml", slideXmlWithListSubtitle("План", ["Собрать требования", "Проверить импорт"], "bullet"));
const bulletBlob = await bulletZip.generateAsync({
type: "blob",
mimeType: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
});
const importedBullet = await importPptxFile(new File([bulletBlob], "Маркированный.pptx", { type: bulletBlob.type }));
expect(importedBullet.slides[0].subtitle).toBe("Собрать требования\nПроверить импорт");
expect(importedBullet.slides[0].subtitleListStyle).toBe("bullet");
const numberZip = new JSZip();
numberZip.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>`
);
numberZip.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>`
);
numberZip.file("ppt/slides/slide1.xml", slideXmlWithListSubtitle("План", ["Шаг один", "Шаг два"], "number"));
const numberBlob = await numberZip.generateAsync({
type: "blob",
mimeType: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
});
const importedNumber = await importPptxFile(new File([numberBlob], "Нумерованный.pptx", { type: numberBlob.type }));
expect(importedNumber.slides[0].subtitle).toBe("Шаг один\nШаг два");
expect(importedNumber.slides[0].subtitleListStyle).toBe("number");
});
it("экспортирует списки подзаголовка PPTX как OOXML bullets", async () => {
const bulletBlob = await exportPptxBlob({
title: "Маркированный.pptx",
slides: [
{
id: "slide-1",
title: "План",
subtitle: "Собрать требования\nПроверить импорт",
subtitleListStyle: "bullet",
notes: "",
theme: "classic"
}
]
});
const bulletZip = await JSZip.loadAsync(await bulletBlob.arrayBuffer());
const bulletSlideXml = (await bulletZip.file("ppt/slides/slide1.xml")?.async("string")) ?? "";
expect(bulletSlideXml).toContain("<a:buChar");
const numberBlob = await exportPptxBlob({
title: "Нумерованный.pptx",
slides: [
{
id: "slide-1",
title: "План",
subtitle: "Шаг один\nШаг два",
subtitleListStyle: "number",
notes: "",
theme: "classic"
}
]
});
const numberZip = await JSZip.loadAsync(await numberBlob.arrayBuffer());
const numberSlideXml = (await numberZip.file("ppt/slides/slide1.xml")?.async("string")) ?? "";
expect(numberSlideXml).toContain("<a:buAutoNum");
});
it("импортирует изображения слайда из PPTX media relationships", async () => {
const zip = new JSZip();
zip.file(
@@ -486,6 +566,14 @@ function slideXmlWithManualBreakSubtitle(title: string, subtitleLines: string[])
.join("")}</a:p></p:txBody></p:sp></p:spTree></p:cSld></p:sld>`;
}
function slideXmlWithListSubtitle(title: string, subtitleLines: string[], listStyle: "bullet" | "number") {
const paragraphProperties =
listStyle === "number" ? '<a:pPr><a:buAutoNum type="arabicPeriod"/></a:pPr>' : '<a:pPr><a:buChar char="•"/></a:pPr>';
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>${subtitleLines
.map((text) => `<a:p>${paragraphProperties}<a:r><a:t>${text}</a:t></a:r></a:p>`)
.join("")}</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>`;
}