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 native export stability
hugohe3de2d851c1f33
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml_context.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml_context.pyindex 909d3fa7..8fb946ac 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml_context.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml_context.py@@ -7,6 +7,14 @@ from xml.etree import ElementTree as ETfrom dataclasses import dataclass, field+@dataclass+class ShapeResult:+ """Internal conversion result carrying XML plus resolved EMU bounds."""++ xml: str+ bounds_emu: tuple[int, int, int, int] | None = None++@dataclassclass ConvertContext:"""Shared context passed through the SVG → DrawingML conversion pipeline.diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml_converter.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml_converter.pyindex 32a3da22..ff7684ad 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml_converter.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml_converter.py@@ -6,7 +6,7 @@ import refrom pathlib import Pathfrom xml.etree import ElementTree as ET-from .drawingml_context import ConvertContext+from .drawingml_context import ConvertContext, ShapeResultfrom .drawingml_utils import (SVG_NS,_extract_inheritable_styles, resolve_url_id,@@ -49,27 +49,11 @@ def parse_transform(transform_str: str) -> tuple[float, float, float, float]:return dx, dy, sx, sy-def _extract_shape_bounds_emu(shape_xml: str) -> tuple[int, int, int, int] | None:- """Extract bounds (x, y, x+cx, y+cy) in EMU from a shape XML string.-- Works for <p:sp>, <p:pic>, and <p:grpSp>.- """- off_match = re.search(r'<a:off x="(-?\d+)" y="(-?\d+)"', shape_xml)- ext_match = re.search(r'<a:ext cx="(\d+)" cy="(\d+)"', shape_xml)- if off_match and ext_match:- x = int(off_match.group(1))- y = int(off_match.group(2))- cx = int(ext_match.group(1))- cy = int(ext_match.group(2))- return (x, y, x + cx, y + cy)- return None--# ---------------------------------------------------------------------------# Group handling# ----------------------------------------------------------------------------def convert_g(elem: ET.Element, ctx: ConvertContext) -> str:+def convert_g(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:"""Convert SVG <g> to DrawingML group shape <p:grpSp>.Preserves group structure so elements can be selected and moved together@@ -85,49 +69,50 @@ def convert_g(elem: ET.Element, ctx: ConvertContext) -> str:style_overrides = _extract_inheritable_styles(elem)child_ctx = ctx.child(dx, dy, sx, sy, filter_id, style_overrides)- child_shapes: list[str] = []+ child_results: list[ShapeResult] = []for child in elem:- shape_xml = convert_element(child, child_ctx)- if shape_xml:- child_shapes.append(shape_xml)+ result = convert_element(child, child_ctx)+ if result:+ child_results.append(result)ctx.sync_from_child(child_ctx)- if not child_shapes:- return ''+ if not child_results:+ return None# Single child: flatten- if len(child_shapes) == 1:- return child_shapes[0]+ if len(child_results) == 1:+ return child_results[0]# Multiple children: wrap in <p:grpSp>min_x = min_y = float('inf')max_x = max_y = float('-inf')- for shape_xml in child_shapes:- bounds = _extract_shape_bounds_emu(shape_xml)- if bounds:- min_x = min(min_x, bounds[0])- min_y = min(min_y, bounds[1])- max_x = max(max_x, bounds[2])- max_y = max(max_y, bounds[3])+ for child_result in child_results:+ bounds = child_result.bounds_emu+ if bounds is None:+ continue+ min_x = min(min_x, bounds[0])+ min_y = min(min_y, bounds[1])+ max_x = max(max_x, bounds[2])+ max_y = max(max_y, bounds[3])if min_x == float('inf'):- return '\n'.join(child_shapes)+ return ShapeResult(xml='\n'.join(result.xml for result in child_results))group_x = int(min_x)group_y = int(min_y)group_w = max(int(max_x - min_x), 1)group_h = max(int(max_y - min_y), 1)- shapes_xml = '\n'.join(child_shapes)+ shapes_xml = '\n'.join(result.xml for result in child_results)group_id = ctx.next_id()group_effect = ''if filter_id and filter_id in ctx.defs:group_effect = build_effect_xml(ctx.defs[filter_id])- return f'''<p:grpSp>+ return ShapeResult(xml=f'''<p:grpSp><p:nvGrpSpPr><p:cNvPr id="{group_id}" name="Group {group_id}"/><p:cNvGrpSpPr/>@@ -143,7 +128,7 @@ def convert_g(elem: ET.Element, ctx: ConvertContext) -> str:{group_effect}</p:grpSpPr>{shapes_xml}-</p:grpSp>'''+</p:grpSp>''', bounds_emu=(group_x, group_y, group_x + group_w, group_y + group_h))# ---------------------------------------------------------------------------@@ -183,7 +168,7 @@ def collect_defs(root: ET.Element) -> dict[str, ET.Element]:return defs-def convert_element(elem: ET.Element, ctx: ConvertContext) -> str:+def convert_element(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:"""Dispatch an SVG element to the appropriate converter."""tag = elem.tag.replace(f'{{{SVG_NS}}}', '')@@ -193,12 +178,12 @@ def convert_element(elem: ET.Element, ctx: ConvertContext) -> str:return converter(elem, ctx)except Exception as e:print(f' Warning: Failed to convert <{tag}>: {e}')- return ''+ return Noneif tag in _NON_VISUAL_TAGS:- return ''+ return None- return ''+ return Nonedef convert_svg_to_slide_shapes(@@ -235,7 +220,7 @@ def convert_svg_to_slide_shapes(continueresult = convert_element(child, ctx)if result:- shapes.append(result)+ shapes.append(result.xml)converted += 1else:if tag not in _NON_VISUAL_TAGS:diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.pyindex 2d8b792b..ddf5e0d5 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py@@ -8,7 +8,7 @@ import base64from typing import Anyfrom xml.etree import ElementTree as ET-from .drawingml_context import ConvertContext+from .drawingml_context import ConvertContext, ShapeResultfrom .drawingml_utils import (SVG_NS, XLINK_NS, ANGLE_UNIT, FONT_PX_TO_HUNDREDTHS_PT, DASH_PRESETS,px_to_emu, _f, _get_attr,@@ -58,7 +58,7 @@ def _wrap_shape(# rect# ----------------------------------------------------------------------------def convert_rect(elem: ET.Element, ctx: ConvertContext) -> str:+def convert_rect(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:"""Convert SVG <rect> to DrawingML shape."""x = ctx_x(_f(elem.get('x')), ctx)y = ctx_y(_f(elem.get('y')), ctx)@@ -66,7 +66,7 @@ def convert_rect(elem: ET.Element, ctx: ConvertContext) -> str:h = ctx_h(_f(elem.get('height')), ctx)if w <= 0 or h <= 0:- return ''+ return Nonefill_op = get_fill_opacity(elem, ctx)stroke_op = get_stroke_opacity(elem, ctx)@@ -88,10 +88,17 @@ def convert_rect(elem: ET.Element, ctx: ConvertContext) -> str:geom = '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>'shape_id = ctx.next_id()- return _wrap_shape(- shape_id, f'Rectangle {shape_id}',- px_to_emu(x), px_to_emu(y), px_to_emu(w), px_to_emu(h),- geom, fill, stroke, effect, rot=rot,+ off_x = px_to_emu(x)+ off_y = px_to_emu(y)+ ext_cx = px_to_emu(w)+ ext_cy = px_to_emu(h)+ return ShapeResult(+ xml=_wrap_shape(+ shape_id, f'Rectangle {shape_id}',+ off_x, off_y, ext_cx, ext_cy,+ geom, fill, stroke, effect, rot=rot,+ ),+ bounds_emu=(off_x, off_y, off_x + ext_cx, off_y + ext_cy),)@@ -201,14 +208,14 @@ def _is_donut_circle(elem: ET.Element, ctx: ConvertContext) -> bool:return True-def convert_circle(elem: ET.Element, ctx: ConvertContext) -> str:+def convert_circle(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:"""Convert SVG <circle> to DrawingML ellipse or donut-arc shape."""cx_ = _f(elem.get('cx'))cy_ = _f(elem.get('cy'))r = _f(elem.get('r'))if r <= 0:- return ''+ return None# --- Donut-chart arc segment detection ---if _is_donut_circle(elem, ctx):@@ -231,7 +238,7 @@ def convert_circle(elem: ET.Element, ctx: ConvertContext) -> str:ctx.scale_x, ctx.scale_y,)if not geom:- return ''+ return None# Use the stroke color/gradient as fill for the arc shapestroke_val = _get_attr(elem, 'stroke', ctx)@@ -253,10 +260,13 @@ def convert_circle(elem: ET.Element, ctx: ConvertContext) -> str:effect = build_effect_xml(ctx.defs[filt_id])shape_id = ctx.next_id()- return _wrap_shape(- shape_id, f'Arc {shape_id}',- min_x, min_y, w_emu, h_emu,- geom, fill, stroke_xml, effect,+ return ShapeResult(+ xml=_wrap_shape(+ shape_id, f'Arc {shape_id}',+ min_x, min_y, w_emu, h_emu,+ geom, fill, stroke_xml, effect,+ ),+ bounds_emu=(min_x, min_y, min_x + w_emu, min_y + h_emu),)# --- Normal circle ---@@ -283,10 +293,17 @@ def convert_circle(elem: ET.Element, ctx: ConvertContext) -> str:geom = '<a:prstGeom prst="ellipse"><a:avLst/></a:prstGeom>'shape_id = ctx.next_id()- return _wrap_shape(- shape_id, f'Ellipse {shape_id}',- px_to_emu(x), px_to_emu(y), px_to_emu(w), px_to_emu(h),- geom, fill, stroke, effect,+ off_x = px_to_emu(x)+ off_y = px_to_emu(y)+ ext_cx = px_to_emu(w)+ ext_cy = px_to_emu(h)+ return ShapeResult(+ xml=_wrap_shape(+ shape_id, f'Ellipse {shape_id}',+ off_x, off_y, ext_cx, ext_cy,+ geom, fill, stroke, effect,+ ),+ bounds_emu=(off_x, off_y, off_x + ext_cx, off_y + ext_cy),)@@ -294,7 +311,7 @@ def convert_circle(elem: ET.Element, ctx: ConvertContext) -> str:# line# ----------------------------------------------------------------------------def convert_line(elem: ET.Element, ctx: ConvertContext) -> str:+def convert_line(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:"""Convert SVG <line> to DrawingML custom geometry shape."""x1 = ctx_x(_f(elem.get('x1')), ctx)y1 = ctx_y(_f(elem.get('y1')), ctx)@@ -334,10 +351,15 @@ def convert_line(elem: ET.Element, ctx: ConvertContext) -> str:rot = int(float(r_match.group(1)) * ANGLE_UNIT)shape_id = ctx.next_id()- return _wrap_shape(- shape_id, f'Line {shape_id}',- px_to_emu(min_x), px_to_emu(min_y), w_emu, h_emu,- geom, '<a:noFill/>', stroke, rot=rot,+ off_x = px_to_emu(min_x)+ off_y = px_to_emu(min_y)+ return ShapeResult(+ xml=_wrap_shape(+ shape_id, f'Line {shape_id}',+ off_x, off_y, w_emu, h_emu,+ geom, '<a:noFill/>', stroke, rot=rot,+ ),+ bounds_emu=(off_x, off_y, off_x + w_emu, off_y + h_emu),)@@ -345,11 +367,11 @@ def convert_line(elem: ET.Element, ctx: ConvertContext) -> str:# path# ----------------------------------------------------------------------------def convert_path(elem: ET.Element, ctx: ConvertContext) -> str:+def convert_path(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:"""Convert SVG <path> to DrawingML custom geometry shape."""d = elem.get('d', '')if not d:- return ''+ return Nonecommands = parse_svg_path(d)commands = svg_path_to_absolute(commands)@@ -373,7 +395,7 @@ def convert_path(elem: ET.Element, ctx: ConvertContext) -> str:)if not path_xml:- return ''+ return Nonew_emu = px_to_emu(width)h_emu = px_to_emu(height)@@ -397,10 +419,15 @@ def convert_path(elem: ET.Element, ctx: ConvertContext) -> str:effect = build_effect_xml(ctx.defs[filt_id])shape_id = ctx.next_id()- return _wrap_shape(- shape_id, f'Freeform {shape_id}',- px_to_emu(min_x), px_to_emu(min_y), w_emu, h_emu,- geom, fill, stroke, effect, rot=rot,+ off_x = px_to_emu(min_x)+ off_y = px_to_emu(min_y)+ return ShapeResult(+ xml=_wrap_shape(+ shape_id, f'Freeform {shape_id}',+ off_x, off_y, w_emu, h_emu,+ geom, fill, stroke, effect, rot=rot,+ ),+ bounds_emu=(off_x, off_y, off_x + w_emu, off_y + h_emu),)@@ -416,11 +443,11 @@ def _parse_points(points_str: str) -> list[tuple[float, float]]:return [(float(nums[i]), float(nums[i + 1])) for i in range(0, len(nums) - 1, 2)]-def convert_polygon(elem: ET.Element, ctx: ConvertContext) -> str:+def convert_polygon(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:"""Convert SVG <polygon> to DrawingML custom geometry shape."""points = _parse_points(elem.get('points', ''))if not points:- return ''+ return Nonecommands = [PathCommand('M', [points[0][0], points[0][1]])]for px_, py_ in points[1:]:@@ -433,7 +460,7 @@ def convert_polygon(elem: ET.Element, ctx: ConvertContext) -> str:)if not path_xml:- return ''+ return Nonew_emu = px_to_emu(width)h_emu = px_to_emu(height)@@ -459,18 +486,23 @@ def convert_polygon(elem: ET.Element, ctx: ConvertContext) -> str:rot = int(float(r_match.group(1)) * ANGLE_UNIT)shape_id = ctx.next_id()- return _wrap_shape(- shape_id, f'Polygon {shape_id}',- px_to_emu(min_x), px_to_emu(min_y), w_emu, h_emu,- geom, fill, stroke, rot=rot,+ off_x = px_to_emu(min_x)+ off_y = px_to_emu(min_y)+ return ShapeResult(+ xml=_wrap_shape(+ shape_id, f'Polygon {shape_id}',+ off_x, off_y, w_emu, h_emu,+ geom, fill, stroke, rot=rot,+ ),+ bounds_emu=(off_x, off_y, off_x + w_emu, off_y + h_emu),)-def convert_polyline(elem: ET.Element, ctx: ConvertContext) -> str:+def convert_polyline(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:"""Convert SVG <polyline> to DrawingML custom geometry shape."""points = _parse_points(elem.get('points', ''))if not points:- return ''+ return Nonecommands = [PathCommand('M', [points[0][0], points[0][1]])]for px_, py_ in points[1:]:@@ -482,7 +514,7 @@ def convert_polyline(elem: ET.Element, ctx: ConvertContext) -> str:)if not path_xml:- return ''+ return Nonew_emu = px_to_emu(width)h_emu = px_to_emu(height)@@ -508,10 +540,15 @@ def convert_polyline(elem: ET.Element, ctx: ConvertContext) -> str:rot = int(float(r_match.group(1)) * ANGLE_UNIT)shape_id = ctx.next_id()- return _wrap_shape(- shape_id, f'Polyline {shape_id}',- px_to_emu(min_x), px_to_emu(min_y), w_emu, h_emu,- geom, '<a:noFill/>', stroke, rot=rot,+ off_x = px_to_emu(min_x)+ off_y = px_to_emu(min_y)+ return ShapeResult(+ xml=_wrap_shape(+ shape_id, f'Polyline {shape_id}',+ off_x, off_y, w_emu, h_emu,+ geom, '<a:noFill/>', stroke, rot=rot,+ ),+ bounds_emu=(off_x, off_y, off_x + w_emu, off_y + h_emu),)@@ -621,7 +658,7 @@ def _build_run_xml(</a:r>'''-def convert_text(elem: ET.Element, ctx: ConvertContext) -> str:+def convert_text(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:"""Convert SVG <text> to DrawingML text shape with multi-run support."""x = ctx_x(_f(elem.get('x')), ctx)y = ctx_y(_f(elem.get('y')), ctx)@@ -650,11 +687,11 @@ def convert_text(elem: ET.Element, ctx: ConvertContext) -> str:runs = _build_text_runs(elem, parent_attrs)if not runs:- return ''+ return Nonefull_text = ''.join(r['text'] for r in runs)if not full_text.strip():- return ''+ return None# Estimate text dimensionstext_width = estimate_text_width(full_text, font_size, font_weight) * 1.15@@ -705,15 +742,19 @@ def convert_text(elem: ET.Element, ctx: ConvertContext) -> str:rot_attr = f' rot="{text_rot}"' if text_rot else ''runs_xml = '\n'.join(_build_run_xml(r, fonts, ctx) for r in runs)+ off_x = px_to_emu(box_x)+ off_y = px_to_emu(box_y)+ ext_cx = px_to_emu(box_w)+ ext_cy = px_to_emu(box_h)- return f'''<p:sp>+ return ShapeResult(xml=f'''<p:sp><p:nvSpPr><p:cNvPr id="{shape_id}" name="TextBox {shape_id}"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr><p:spPr>-<a:xfrm{rot_attr}><a:off x="{px_to_emu(box_x)}" y="{px_to_emu(box_y)}"/>-<a:ext cx="{px_to_emu(box_w)}" cy="{px_to_emu(box_h)}"/></a:xfrm>+<a:xfrm{rot_attr}><a:off x="{off_x}" y="{off_y}"/>+<a:ext cx="{ext_cx}" cy="{ext_cy}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/><a:ln><a:noFill/></a:ln>@@ -729,18 +770,18 @@ def convert_text(elem: ET.Element, ctx: ConvertContext) -> str:{runs_xml}</a:p></p:txBody>-</p:sp>'''+</p:sp>''', bounds_emu=(off_x, off_y, off_x + ext_cx, off_y + ext_cy))# ---------------------------------------------------------------------------# image# ----------------------------------------------------------------------------def convert_image(elem: ET.Element, ctx: ConvertContext) -> str:+def convert_image(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:"""Convert SVG <image> to DrawingML picture element."""href = elem.get('href') or elem.get(f'{{{XLINK_NS}}}href')if not href:- return ''+ return Nonex = ctx_x(_f(elem.get('x')), ctx)y = ctx_y(_f(elem.get('y')), ctx)@@ -748,26 +789,26 @@ def convert_image(elem: ET.Element, ctx: ConvertContext) -> str:h = ctx_h(_f(elem.get('height')), ctx)if w <= 0 or h <= 0:- return ''+ return None# Extract image dataif href.startswith('data:'):match = re.match(r'data:image/(\w+);base64,(.+)', href, re.DOTALL)if not match:- return ''+ return Noneimg_format = match.group(1).lower()if img_format == 'jpeg':img_format = 'jpg'img_data = base64.b64decode(match.group(2))else:if ctx.svg_dir is None:- return ''+ return Noneimg_path = ctx.svg_dir / hrefif not img_path.exists():img_path = ctx.svg_dir.parent / hrefif not img_path.exists():print(f' Warning: External image not found: {href}')- return ''+ return Noneimg_format = img_path.suffix.lstrip('.').lower()if img_format == 'jpeg':img_format = 'jpg'@@ -793,8 +834,12 @@ def convert_image(elem: ET.Element, ctx: ConvertContext) -> str:rot_attr = f' rot="{rot}"' if rot else ''shape_id = ctx.next_id()+ off_x = px_to_emu(x)+ off_y = px_to_emu(y)+ ext_cx = px_to_emu(w)+ ext_cy = px_to_emu(h)- return f'''<p:pic>+ return ShapeResult(xml=f'''<p:pic><p:nvPicPr><p:cNvPr id="{shape_id}" name="Image {shape_id}"/><p:cNvPicPr><a:picLocks noChangeAspect="1"/></p:cNvPicPr>@@ -805,18 +850,18 @@ def convert_image(elem: ET.Element, ctx: ConvertContext) -> str:<a:stretch><a:fillRect/></a:stretch></p:blipFill><p:spPr>-<a:xfrm{rot_attr}><a:off x="{px_to_emu(x)}" y="{px_to_emu(y)}"/>-<a:ext cx="{px_to_emu(w)}" cy="{px_to_emu(h)}"/></a:xfrm>+<a:xfrm{rot_attr}><a:off x="{off_x}" y="{off_y}"/>+<a:ext cx="{ext_cx}" cy="{ext_cy}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr>-</p:pic>'''+</p:pic>''', bounds_emu=(off_x, off_y, off_x + ext_cx, off_y + ext_cy))# ---------------------------------------------------------------------------# ellipse# ----------------------------------------------------------------------------def convert_ellipse(elem: ET.Element, ctx: ConvertContext) -> str:+def convert_ellipse(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:"""Convert SVG <ellipse> to DrawingML ellipse shape."""cx_ = ctx_x(_f(elem.get('cx')), ctx)cy_ = ctx_y(_f(elem.get('cy')), ctx)@@ -824,7 +869,7 @@ def convert_ellipse(elem: ET.Element, ctx: ConvertContext) -> str:ry = _f(elem.get('ry')) * ctx.scale_yif rx <= 0 or ry <= 0:- return ''+ return Nonex = cx_ - rxy = cy_ - ry@@ -846,8 +891,15 @@ def convert_ellipse(elem: ET.Element, ctx: ConvertContext) -> str:rot = int(float(r_match.group(1)) * ANGLE_UNIT)shape_id = ctx.next_id()- return _wrap_shape(- shape_id, f'Ellipse {shape_id}',- px_to_emu(x), px_to_emu(y), px_to_emu(w), px_to_emu(h),- geom, fill, stroke, rot=rot,+ off_x = px_to_emu(x)+ off_y = px_to_emu(y)+ ext_cx = px_to_emu(w)+ ext_cy = px_to_emu(h)+ return ShapeResult(+ xml=_wrap_shape(+ shape_id, f'Ellipse {shape_id}',+ off_x, off_y, ext_cx, ext_cy,+ geom, fill, stroke, rot=rot,+ ),+ bounds_emu=(off_x, off_y, off_x + ext_cx, off_y + ext_cy),)diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_builder.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_builder.pyindex 5ade3d7c..472d3629 100644--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_builder.py+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_builder.py@@ -2,6 +2,8 @@from __future__ import annotations+import hashlib+import reimport shutilimport tempfileimport zipfile@@ -36,6 +38,31 @@ except ImportError:create_transition_xml = None+def _append_relationship(+ rels_path: Path,+ rel_type: str,+ target: str,+) -> str:+ """Append a relationship entry with the next available rId."""+ with open(rels_path, 'r', encoding='utf-8') as f:+ rels_content = f.read()++ rid_numbers = [int(match) for match in re.findall(r'Id="rId(\d+)"', rels_content)]+ next_rid = f'rId{max(rid_numbers, default=0) + 1}'+ rel_xml = (+ f' <Relationship Id="{next_rid}" '+ f'Type="{rel_type}" Target="{target}"/>'+ )+ rels_content = rels_content.replace(+ '</Relationships>', rel_xml + '\n</Relationships>',+ )++ with open(rels_path, 'w', encoding='utf-8') as f:+ f.write(rels_content)++ return next_rid++def create_pptx_with_native_svg(svg_files: list[Path],output_path: Path,@@ -150,6 +177,8 @@ def create_pptx_with_native_svg(success_count = 0has_any_image = False+ media_cache: dict[tuple[str, str], str] = {}+ notes_slides_created: set[int] = set()for i, svg_path in enumerate(svg_files, 1):slide_num = i@@ -179,9 +208,29 @@ def create_pptx_with_native_svg(f.write(slide_xml)# Write media files+ media_name_map: dict[str, str] = {}for media_name, media_data in media_files_dict.items():- with open(media_dir / media_name, 'wb') as f:- f.write(media_data)+ ext = media_name.rsplit('.', 1)[-1].lower()+ media_hash = hashlib.sha256(media_data).hexdigest()+ cache_key = (ext, media_hash)+ cached_name = media_cache.get(cache_key)++ if cached_name is None:+ cached_name = media_name+ media_cache[cache_key] = cached_name+ with open(media_dir / cached_name, 'wb') as f:+ f.write(media_data)++ media_name_map[media_name] = cached_name++ for rel in rel_entries:+ target = rel.get('target', '')+ if not target.startswith('../media/'):+ continue+ media_name = target.split('../media/', 1)[1]+ mapped_name = media_name_map.get(media_name)+ if mapped_name:+ rel['target'] = f'../media/{mapped_name}'# Build relationships XMLrels_dir = extract_dir / 'ppt' / 'slides' / '_rels'@@ -262,35 +311,28 @@ def create_pptx_with_native_svg(svg_stem = svg_path.stemnotes_content = notes.get(svg_stem, '') if notes else ''notes_text = markdown_to_plain_text(notes_content) if notes_content else ''-- notes_slides_dir = extract_dir / 'ppt' / 'notesSlides'- notes_slides_dir.mkdir(exist_ok=True)-- notes_xml_path = notes_slides_dir / f'notesSlide{slide_num}.xml'- notes_xml = create_notes_slide_xml(slide_num, notes_text)- with open(notes_xml_path, 'w', encoding='utf-8') as f:- f.write(notes_xml)-- notes_rels_dir = notes_slides_dir / '_rels'- notes_rels_dir.mkdir(exist_ok=True)- notes_rels_path = notes_rels_dir / f'notesSlide{slide_num}.xml.rels'- notes_rels_xml = create_notes_slide_rels_xml(slide_num)- with open(notes_rels_path, 'w', encoding='utf-8') as f:- f.write(notes_rels_xml)-- # Update slide.xml.rels to add notes association- with open(rels_path, 'r', encoding='utf-8') as f:- slide_rels_content = f.read()- notes_rel = (- f' <Relationship Id="rId10" '- f'Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide" '- f'Target="../notesSlides/notesSlide{slide_num}.xml"/>'- )- slide_rels_content = slide_rels_content.replace(- '</Relationships>', notes_rel + '\n</Relationships>',- )- with open(rels_path, 'w', encoding='utf-8') as f:- f.write(slide_rels_content)+ if notes_text:+ notes_slides_dir = extract_dir / 'ppt' / 'notesSlides'+ notes_slides_dir.mkdir(exist_ok=True)++ notes_xml_path = notes_slides_dir / f'notesSlide{slide_num}.xml'+ notes_xml = create_notes_slide_xml(slide_num, notes_text)+ with open(notes_xml_path, 'w', encoding='utf-8') as f:+ f.write(notes_xml)++ notes_rels_dir = notes_slides_dir / '_rels'+ notes_rels_dir.mkdir(exist_ok=True)+ notes_rels_path = notes_rels_dir / f'notesSlide{slide_num}.xml.rels'+ notes_rels_xml = create_notes_slide_rels_xml(slide_num)+ with open(notes_rels_path, 'w', encoding='utf-8') as f:+ f.write(notes_rels_xml)++ _append_relationship(+ rels_path,+ 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide',+ f'../notesSlides/notesSlide{slide_num}.xml',+ )+ notes_slides_created.add(slide_num)if verbose:if use_native_shapes:@@ -299,7 +341,7 @@ def create_pptx_with_native_svg(mode_str = " (PNG+SVG)" if has_any_image else " (SVG)"else:mode_str = " (SVG)"- has_notes = enable_notes and bool(notes_content)+ has_notes = slide_num in notes_slides_creatednotes_str = " +notes" if has_notes else ""print(f" [{i}/{len(svg_files)}] {svg_path.name}{mode_str}{notes_str}")@@ -333,8 +375,8 @@ def create_pptx_with_native_svg(f.write(content_types)# Add notesSlides content types- if enable_notes:- for i in range(1, len(svg_files) + 1):+ if enable_notes and notes_slides_created:+ for i in sorted(notes_slides_created):override = (f' <Override PartName="/ppt/notesSlides/notesSlide{i}.xml" 'f'ContentType="application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml"/>'