Skip to content

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 inline whitespace at tspan boundaries

hugohe308350b53bfa6
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py
index 1a71c963..150defdb 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py
@@ -773,10 +773,20 @@ def convert_polyline(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | Non
# ---------------------------------------------------------------------------
def _normalize_text(text: str) -> str:
- """Collapse internal whitespace/newlines into a single space, strip ends."""
+ """Collapse runs of whitespace into a single space; do NOT strip the ends.
+
+ Stripping at this layer would silently delete the inline boundary
+ spaces in nested-tspan structures like
+ ``<tspan>foo <tspan>bar</tspan> baz</tspan>``: the parent's text
+ ("foo ") and the child's tail (" baz") would each lose the only space
+ that separated them from the inner run, producing "foobarbaz".
+
+ The paragraph's overall leading / trailing whitespace is removed once
+ in ``_build_text_runs`` after all inline runs have been concatenated.
+ """
if not text:
return ''
- return re.sub(r'\s+', ' ', text).strip()
+ return re.sub(r'\s+', ' ', text)
def _override_run_attrs(
@@ -858,6 +868,14 @@ def _build_text_runs(
if t:
runs.append({**parent_attrs, 'text': t})
+ # Strip the paragraph's overall leading / trailing whitespace once,
+ # while keeping every inline boundary space intact. Per-run normalize
+ # deliberately leaves boundary spaces (see `_normalize_text`).
+ if runs:
+ runs[0]['text'] = runs[0]['text'].lstrip(' ')
+ runs[-1]['text'] = runs[-1]['text'].rstrip(' ')
+ runs = [r for r in runs if r['text']]
+
return runs