AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He
fix(svg-to-pptx): preserve actual blank layout relationships
hugohe3fe42e7c4705c
diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.pyindex 759a288a..4fff25a8 100644--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py@@ -15,9 +15,11 @@ import tempfileimport uuidimport zipfilefrom concurrent.futures import ProcessPoolExecutor, as_completed+from dataclasses import dataclassfrom datetime import datetime, timezonefrom pathlib import Pathfrom typing import Any+from xml.etree import ElementTree as ETfrom xml.sax.saxutils import escapefrom pptx import Presentation@@ -69,6 +71,56 @@ except ImportError:pick_animation_effect = None+SLIDE_LAYOUT_REL_TYPE = (+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout"+)+++@dataclass(frozen=True)+class PptxStructureContext:+ """Resolved base package structure reused when slide XML is regenerated."""++ slide_layout_targets: dict[int, str]++ def slide_layout_target(self, slide_num: int) -> str:+ """Return the slide layout target for a generated slide."""+ try:+ return self.slide_layout_targets[slide_num]+ except KeyError as exc:+ raise RuntimeError(+ f"Missing slide layout relationship for generated slide {slide_num}"+ ) from exc+++def _relationship_attrs(elem: ET.Element) -> dict[str, str]:+ return {key.rsplit("}", 1)[-1]: value for key, value in elem.attrib.items()}+++def _read_slide_layout_targets(extract_dir: Path, slide_count: int) -> PptxStructureContext:+ """Read the actual layout relationship target for every generated slide."""+ slide_layout_targets: dict[int, str] = {}+ rels_dir = extract_dir / "ppt" / "slides" / "_rels"+ for slide_num in range(1, slide_count + 1):+ rels_path = rels_dir / f"slide{slide_num}.xml.rels"+ if not rels_path.exists():+ raise RuntimeError(f"Missing slide relationship file: {rels_path}")+ root = ET.parse(rels_path).getroot()+ for elem in root:+ attrs = _relationship_attrs(elem)+ if attrs.get("Type") != SLIDE_LAYOUT_REL_TYPE:+ continue+ target = attrs.get("Target")+ if not target:+ raise RuntimeError(+ f"Slide {slide_num} layout relationship has no Target"+ )+ slide_layout_targets[slide_num] = target+ break+ if slide_num not in slide_layout_targets:+ raise RuntimeError(f"Slide {slide_num} has no slide layout relationship")+ return PptxStructureContext(slide_layout_targets=slide_layout_targets)++def _append_relationship(rels_path: Path,rel_type: str,@@ -778,6 +830,7 @@ def create_pptx_with_native_svg(extract_dir = temp_dir / 'pptx_content'with zipfile.ZipFile(base_pptx, 'r') as zf:zf.extractall(extract_dir)+ structure = _read_slide_layout_targets(extract_dir, len(svg_files))media_dir = extract_dir / 'ppt' / 'media'media_dir.mkdir(exist_ok=True)@@ -957,8 +1010,8 @@ def create_pptx_with_native_svg(rels_xml = f'''<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1"- Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout"- Target="../slideLayouts/slideLayout1.xml"/>{extra_rels}+ Type="{SLIDE_LAYOUT_REL_TYPE}"+ Target="{structure.slide_layout_target(slide_num)}"/>{extra_rels}</Relationships>'''with open(rels_path, 'w', encoding='utf-8') as f:f.write(rels_xml)@@ -1031,6 +1084,7 @@ def create_pptx_with_native_svg(png_rid=png_rid, png_filename=png_filename,svg_rid=svg_rid, svg_filename=svg_filename,use_compat_mode=(use_compat_mode and slide_has_png),+ slide_layout_target=structure.slide_layout_target(slide_num),)with open(rels_path, 'w', encoding='utf-8') as f:f.write(rels_xml)diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/slide_xml.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/slide_xml.pyindex da326225..04835879 100644--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/slide_xml.py+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/slide_xml.py@@ -111,6 +111,7 @@ def create_slide_rels_xml(svg_rid: str,svg_filename: str,use_compat_mode: bool = True,+ slide_layout_target: str = "../slideLayouts/slideLayout1.xml",) -> str:"""Create slide relationship file XML.@@ -120,17 +121,18 @@ def create_slide_rels_xml(svg_rid: SVG relationship ID.svg_filename: SVG filename.use_compat_mode: Whether to use compatibility mode.+ slide_layout_target: Target for the slide's actual layout part."""if use_compat_mode:return f'''<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">- <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout1.xml"/>+ <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="{slide_layout_target}"/><Relationship Id="{png_rid}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/{png_filename}"/><Relationship Id="{svg_rid}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/{svg_filename}"/></Relationships>'''else:return f'''<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">- <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout1.xml"/>+ <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="{slide_layout_target}"/><Relationship Id="{svg_rid}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/{svg_filename}"/></Relationships>'''