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-finalize): detect SVG documents that start with an XML declaration

hugohe384b311019f14
diff --git a/skills/ppt-master/scripts/svg_finalize/embed_images.py b/skills/ppt-master/scripts/svg_finalize/embed_images.py
index 08be8b7c..482faa86 100644
--- a/skills/ppt-master/scripts/svg_finalize/embed_images.py
+++ b/skills/ppt-master/scripts/svg_finalize/embed_images.py
@@ -28,6 +28,18 @@ from console_encoding import configure_utf8_stdio # noqa: E402
configure_utf8_stdio()
+_SVG_DOCUMENT_START_RE = re.compile(
+ br"\A(?:\xef\xbb\xbf)?[ \t\r\n]*"
+ br"(?:<\?xml(?=[ \t\r\n])(?:[^?]|\?(?!>))*\?>[ \t\r\n]*)?"
+ br"(?:(?:"
+ br"<!--(?:[^-]|-(?!-))*-->"
+ br"|<!DOCTYPE[ \t\r\n]+svg(?=[ \t\r\n\[>])"
+ br"(?:[^>\"']|\"[^\"]*\"|'[^']*')*>"
+ br")[ \t\r\n]*)*"
+ br"<svg(?:[ \t\r\n:]|/?>|\Z)"
+)
+
+
def get_mime_type(filename: str, file_bytes: bytes | None = None) -> str:
"""Return the MIME type based on file bytes first, then extension."""
if file_bytes:
@@ -39,7 +51,7 @@ def get_mime_type(filename: str, file_bytes: bytes | None = None) -> str:
return 'image/gif'
if file_bytes.startswith(b"RIFF") and file_bytes[8:12] == b"WEBP":
return 'image/webp'
- if file_bytes.lstrip().startswith(b"<svg"):
+ if _SVG_DOCUMENT_START_RE.match(file_bytes):
return 'image/svg+xml'
ext = filename.lower().split('.')[-1]