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-editor): keep user ids that share the temp prefix; parse ".5" numbers

hugohe3264bd66908e5
diff --git a/skills/ppt-master/scripts/svg_editor/annotations.py b/skills/ppt-master/scripts/svg_editor/annotations.py
index d7e252ef..8d20ff86 100644
--- a/skills/ppt-master/scripts/svg_editor/annotations.py
+++ b/skills/ppt-master/scripts/svg_editor/annotations.py
@@ -26,6 +26,10 @@ ET.register_namespace('', SVG_NS)
ET.register_namespace('xlink', XLINK_NS)
+# Only ids this tool generates; a user id like "_edit_gradient" is not transient.
+_TEMP_ID_RE = re.compile(r'_edit_\d+')
+
+
def assign_temp_ids(root: ET.Element) -> None:
"""Assign deterministic temp ids (_edit_0, _edit_1, ...) to elements without one.
@@ -34,7 +38,7 @@ def assign_temp_ids(root: ET.Element) -> None:
"""
for elem in root.iter():
eid = elem.get('id', '')
- if eid.startswith('_edit_'):
+ if _TEMP_ID_RE.fullmatch(eid):
elem.attrib.pop('id', None)
counter = 0
@@ -72,7 +76,7 @@ def _local_name(elem: ET.Element) -> str:
def _first_number(value: Optional[str]) -> Optional[float]:
if value is None:
return None
- match = re.search(r'-?\d+(?:\.\d+)?', value)
+ match = re.search(r'[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?', value)
return float(match.group(0)) if match else None
@@ -336,5 +340,5 @@ def strip_unused_temp_ids(root: ET.Element, keep_ids: set) -> None:
protected.add(eid)
for elem in root.iter():
eid = elem.get('id', '')
- if eid.startswith('_edit_') and eid not in protected:
+ if _TEMP_ID_RE.fullmatch(eid) and eid not in protected:
elem.attrib.pop('id', None)
diff --git a/skills/ppt-master/scripts/tests/test_svg_editor_server.py b/skills/ppt-master/scripts/tests/test_svg_editor_server.py
index f49c3848..c9fc619e 100644
--- a/skills/ppt-master/scripts/tests/test_svg_editor_server.py
+++ b/skills/ppt-master/scripts/tests/test_svg_editor_server.py
@@ -194,3 +194,31 @@ class StagingDraftTests(unittest.TestCase):
body = self._client().post('/api/save-all').get_json()
self.assertEqual(body, {'status': 'ok', 'files_modified': [], 'draft_saved': True})
self.assertFalse(self.draft.exists())
+
+
+class AnnotationHelperTests(unittest.TestCase):
+ def test_user_ids_with_the_temp_prefix_are_kept(self) -> None:
+ from xml.etree import ElementTree as ET
+ from svg_editor.annotations import assign_temp_ids, strip_unused_temp_ids
+
+ root = ET.fromstring(
+ '<svg><defs><linearGradient id="_edit_gradient"/></defs>'
+ '<rect fill="url(#_edit_gradient)"/><text id="_edit_7">T</text></svg>'
+ )
+ assign_temp_ids(root)
+ strip_unused_temp_ids(root, set())
+ ids = {elem.get('id') for elem in root.iter()}
+ self.assertIn('_edit_gradient', ids)
+ self.assertNotIn('_edit_7', ids)
+
+ def test_leading_dot_numbers_keep_following_line_in_place(self) -> None:
+ from xml.etree import ElementTree as ET
+ from svg_editor.annotations import promote_tspan_to_text
+
+ root = ET.fromstring(
+ '<svg><text y="100" x="0"><tspan id="a" dy=".5">A</tspan>'
+ '<tspan id="b" dy=".5">B</tspan></text></svg>'
+ )
+ self.assertEqual(promote_tspan_to_text(root, 'a', '20', '30'), (True, None))
+ following = next(elem for elem in root.iter() if elem.get('id') == 'b')
+ self.assertEqual(float(following.get('dy')), 1.0)