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(checker): judge class, id, and event attributes on parsed attributes

hugohe38f00128e21c3
diff --git a/skills/ppt-master/scripts/svg_quality/svg_contracts.py b/skills/ppt-master/scripts/svg_quality/svg_contracts.py
index ba6e829c..b4dee0a8 100644
--- a/skills/ppt-master/scripts/svg_quality/svg_contracts.py
+++ b/skills/ppt-master/scripts/svg_quality/svg_contracts.py
@@ -203,6 +203,11 @@ def check_forbidden_elements(
content_lower = content.lower()
elems = list(root.iter())
local_names = {_local_name(elem).lower() for elem in elems}
+ # Parsed attribute names, not raw text: "data-class" or a <text> reading
+ # "class=Customer" / "onload=init" is not an attribute.
+ attr_names = {
+ name.rsplit("}", 1)[-1].lower() for elem in elems for name in elem.attrib
+ }
# ============================================================
# Forbidden elements blocklist - PPT incompatible
@@ -211,12 +216,12 @@ def check_forbidden_elements(
# Style system
if 'style' in local_names:
result['errors'].append("Detected forbidden <style> element (use inline attributes instead)")
- if re.search(r'\bclass\s*=', content):
+ if 'class' in attr_names:
result['errors'].append("Detected forbidden class attribute (use inline styles instead)")
# id attribute: only report error when <style> also exists (id is harmful only with CSS selectors)
# id inside <defs> for linearGradient/filter etc. is required, Inkscape also auto-adds id to elements,
# standalone id attributes have no impact on PPT export
- if 'style' in local_names and re.search(r'\bid\s*=', content):
+ if 'style' in local_names and 'id' in attr_names:
result['errors'].append(
"Detected id attribute used with <style> (CSS selectors forbidden, use inline styles instead)"
)
@@ -271,7 +276,7 @@ def check_forbidden_elements(
result['errors'].append("Detected forbidden SMIL animation element <set> (SVG animations are not exported)")
if 'script' in local_names:
result['errors'].append("Detected forbidden <script> element (scripts and event handlers forbidden)")
- if re.search(r'\bon\w+\s*=', content): # onclick, onload etc.
+ if any(re.fullmatch(r'on\w+', name) for name in attr_names): # onclick, onload etc.
result['errors'].append("Detected forbidden event attributes (e.g., onclick, onload)")
# Other discouraged elements
diff --git a/skills/ppt-master/scripts/tests/test_svg_quality_checker.py b/skills/ppt-master/scripts/tests/test_svg_quality_checker.py
index 6ec14139..46f19463 100644
--- a/skills/ppt-master/scripts/tests/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/tests/test_svg_quality_checker.py
@@ -488,3 +488,23 @@ class NoCropStretchMeasurementTests(unittest.TestCase):
SVGQualityChecker._stretch_deviation(plain, (900, 1600)), 0.0
)
self.assertIsNone(SVGQualityChecker._stretch_deviation(nested, None))
+
+
+class ForbiddenAttributeTests(unittest.TestCase):
+ def _errors(self, body: str) -> list[str]:
+ from svg_quality.svg_contracts import check_forbidden_elements
+
+ svg = f'<svg xmlns="http://www.w3.org/2000/svg">{body}</svg>'
+ result = {"errors": [], "warnings": []}
+ check_forbidden_elements(svg, ET.fromstring(svg), result)
+ return result["errors"]
+
+ def test_text_and_data_attributes_are_not_forbidden_attributes(self) -> None:
+ for body in ('<g data-class="content"/>', "<text>class=Customer</text>",
+ "<text>onload=initialize</text>"):
+ with self.subTest(body=body):
+ self.assertEqual(self._errors(body), [])
+
+ def test_real_class_and_event_attributes_still_fail(self) -> None:
+ self.assertTrue(self._errors('<g class="a"/>'))
+ self.assertTrue(self._errors('<rect onclick="x()"/>'))