Preserve QPowerPoint paragraph breaks on import
This commit is contained in:
@@ -129,6 +129,28 @@ describe("powerPointOffice helpers", () => {
|
||||
expect(imported.slides[0].notes).toBe("Заметка докладчика");
|
||||
});
|
||||
|
||||
it("сохраняет переносы абзацев внутри текстового блока 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", slideXmlWithMultilineSubtitle("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(
|
||||
@@ -340,6 +362,12 @@ function slideXmlWithTextStyles(title: string, subtitle: 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:rPr sz="3400"><a:solidFill><a:srgbClr val="C2410C"/></a:solidFill><a:latin typeface="Courier New"/></a:rPr><a:t>${title}</a:t></a:r></a:p></p:txBody></p:sp><p:sp><p:txBody><a:p><a:r><a:rPr sz="2200"><a:solidFill><a:srgbClr val="0F766E"/></a:solidFill><a:latin typeface="Times New Roman"/></a:rPr><a:t>${subtitle}</a:t></a:r></a:p></p:txBody></p:sp></p:spTree></p:cSld></p:sld>`;
|
||||
}
|
||||
|
||||
function slideXmlWithMultilineSubtitle(title: string, subtitleParagraphs: 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>${subtitleParagraphs
|
||||
.map((text) => `<a:p><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>`;
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ function extractSlideTextBlocks(slideXml: unknown): SlideTextBlock[] {
|
||||
const textBodies = recordsByKey(slideXml, "txBody");
|
||||
const blocks = textBodies
|
||||
.map((textBody) => {
|
||||
const text = normalizeWhitespace(extractTextBlocks(textBody).join("\n"));
|
||||
const text = extractTextBodyText(textBody);
|
||||
if (!text) {
|
||||
return null;
|
||||
}
|
||||
@@ -199,6 +199,14 @@ function extractSlideTextBlocks(slideXml: unknown): SlideTextBlock[] {
|
||||
return blocks.length > 0 ? blocks : extractTextBlocks(slideXml).map((text) => ({ text }));
|
||||
}
|
||||
|
||||
function extractTextBodyText(textBody: Record<string, unknown>) {
|
||||
const paragraphs = toArray(textBody.p)
|
||||
.map((paragraph) => normalizeWhitespace(extractTextBlocks(paragraph).join("")))
|
||||
.filter(Boolean);
|
||||
|
||||
return paragraphs.length > 0 ? paragraphs.join("\n") : normalizeWhitespace(extractTextBlocks(textBody).join("\n"));
|
||||
}
|
||||
|
||||
export function listSlidePaths(
|
||||
zip: ZipArchive,
|
||||
presentationXml?: unknown,
|
||||
|
||||
Reference in New Issue
Block a user