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(spec-lock): unify image row parsing across consumers

hugohe306036a850339
diff --git a/skills/ppt-master/scripts/page_context.py b/skills/ppt-master/scripts/page_context.py
index 0435f5a8..7ee24f75 100644
--- a/skills/ppt-master/scripts/page_context.py
+++ b/skills/ppt-master/scripts/page_context.py
@@ -29,6 +29,7 @@ from typing import Callable, Iterable
from project_specs import (
default_spec_lock_forbidden,
parse_markdown_artifact,
+ parse_spec_lock_artifact,
validate_project_artifacts,
)
from svg_to_pptx.pptx_package.template_structure import (
@@ -460,7 +461,7 @@ def build_page_context(project: str | Path, raw_page: str) -> PageContextResult:
f"{preview}{suffix}"
)
try:
- lock_sections_raw = parse_markdown_artifact(
+ lock_sections_raw = parse_spec_lock_artifact(
lock_path,
report_duplicate_fields=True,
)
diff --git a/skills/ppt-master/scripts/project_specs.py b/skills/ppt-master/scripts/project_specs.py
index 4206c0af..bdd55991 100644
--- a/skills/ppt-master/scripts/project_specs.py
+++ b/skills/ppt-master/scripts/project_specs.py
@@ -69,6 +69,9 @@ _MARKDOWN_DATA_LINE_RE = re.compile(
r"^[ \t]*-[ \t]+(?:\*\*)?([^:\n*]+?)(?:\*\*)?[ \t]*:[ \t]*(.*)$",
re.MULTILINE,
)
+_IMAGE_PATH_SUFFIXES = frozenset(
+ {".bmp", ".gif", ".jpeg", ".jpg", ".png", ".svg", ".tif", ".tiff", ".webp"}
+)
_SCAFFOLD_TOKEN_RE = re.compile(r"\{\{[A-Z_]+\}\}")
_SCHEMA_MARKER_RE = re.compile(
r"^<!--[ \t]+ppt-master-schema:[ \t]*([a-z0-9-]+/v[1-9][0-9]*)[ \t]+-->$",
@@ -165,6 +168,90 @@ def parse_markdown_artifact(
return sections
+def _looks_like_image_path(raw: str) -> bool:
+ """Return whether one lock token looks like a project image path."""
+ token = raw.strip().strip("`'\"").replace("\\", "/")
+ return bool(token) and Path(token).suffix.casefold() in _IMAGE_PATH_SUFFIXES
+
+
+def parse_spec_lock_artifact(
+ lock_path: Path,
+ *,
+ report_duplicate_fields: bool = False,
+ compatibility_warnings: list[str] | None = None,
+) -> list[dict[str, object]]:
+ """Parse one execution lock and normalize supported legacy image rows.
+
+ New locks use ``- <key>: <path> | source=... | pattern=... | crop=...``.
+ Some versioned projects instead placed the image path before the colon.
+ Preserve those projects by projecting the key path back into the value so
+ every consumer sees the same path-first image value.
+ """
+ sections = parse_markdown_artifact(
+ lock_path,
+ report_duplicate_fields=report_duplicate_fields,
+ )
+ normalized_sections: list[dict[str, object]] = []
+ compatibility_keys: list[str] = []
+
+ for section in sections:
+ if str(section.get("heading", "")).strip().casefold() != "images":
+ normalized_sections.append(section)
+ continue
+ raw_fields = section.get("fields")
+ if not isinstance(raw_fields, dict):
+ normalized_sections.append(section)
+ continue
+
+ fields: dict[str, str] = {}
+ for raw_key, raw_value in raw_fields.items():
+ key = str(raw_key)
+ value = str(raw_value).strip()
+ value_path = value.split("|", 1)[0].strip()
+ if _looks_like_image_path(key) and not _looks_like_image_path(value_path):
+ value = f"{key} | {value}" if value else key
+ compatibility_keys.append(key)
+ fields[key] = value
+
+ normalized_section = dict(section)
+ normalized_section["fields"] = fields
+ normalized_sections.append(normalized_section)
+
+ if compatibility_warnings is not None and compatibility_keys:
+ sample = ", ".join(compatibility_keys[:3])
+ suffix = "" if len(compatibility_keys) <= 3 else ", ..."
+ compatibility_warnings.append(
+ f"{lock_path.name} images: normalized {len(compatibility_keys)} legacy "
+ "path-as-key row(s); new locks should use '- <key>: <path> | "
+ "source=... | pattern=... | crop=...' "
+ f"(found: {sample}{suffix})"
+ )
+ return normalized_sections
+
+
+def parse_spec_lock(
+ lock_path: Path,
+ *,
+ report_duplicate_fields: bool = False,
+ compatibility_warnings: list[str] | None = None,
+) -> dict[str, dict[str, str]]:
+ """Return one execution lock as ``{section: {key: value}}`."""
+ sections = parse_spec_lock_artifact(
+ lock_path,
+ report_duplicate_fields=report_duplicate_fields,
+ compatibility_warnings=compatibility_warnings,
+ )
+ parsed: dict[str, dict[str, str]] = {}
+ for section in sections:
+ raw_fields = section.get("fields")
+ if not isinstance(raw_fields, dict):
+ continue
+ parsed[str(section.get("heading", "")).strip()] = {
+ str(key): str(value) for key, value in raw_fields.items()
+ }
+ return parsed
+
+
def default_spec_lock_forbidden() -> frozenset[str]:
"""Return the versioned scaffold's universal forbidden-item defaults."""
sections = parse_markdown_artifact(SCAFFOLD_DIR / "spec_lock.md")
@@ -1022,6 +1109,14 @@ def validate_project_artifacts(
artifact_errors = validate_markdown_schema(artifact_path, schema_path)
errors.extend(artifact_errors)
if artifact_kind == "lock" and not artifact_errors:
+ try:
+ parse_spec_lock_artifact(
+ artifact_path,
+ compatibility_warnings=warnings,
+ )
+ except (OSError, UnicodeError, ValueError) as exc:
+ errors.append(f"spec_lock.md compatibility parse failed: {exc}")
+ continue
versioned_lock_valid = True
if versioned_lock_valid:
try:
diff --git a/skills/ppt-master/scripts/svg_quality_checker.py b/skills/ppt-master/scripts/svg_quality_checker.py
index d354a02e..7ceaa631 100644
--- a/skills/ppt-master/scripts/svg_quality_checker.py
+++ b/skills/ppt-master/scripts/svg_quality_checker.py
@@ -52,7 +52,7 @@ from svg_to_pptx.canvas_contract import (
)
try:
- from update_spec import parse_lock as _parse_spec_lock
+ from project_specs import parse_spec_lock as _parse_spec_lock
except ImportError:
_parse_spec_lock = None # spec_lock anchor comparison will be skipped
diff --git a/skills/ppt-master/scripts/update_spec.py b/skills/ppt-master/scripts/update_spec.py
index 88a24865..61386387 100755
--- a/skills/ppt-master/scripts/update_spec.py
+++ b/skills/ppt-master/scripts/update_spec.py
@@ -28,6 +28,7 @@ import sys
from pathlib import Path
from console_encoding import configure_utf8_stdio
+from project_specs import parse_spec_lock as parse_lock
configure_utf8_stdio()
@@ -35,29 +36,6 @@ HEX_RE = re.compile(r"^#(?:[0-9A-Fa-f]{3,4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$")
FONT_FAMILY_RE = re.compile(r"""(font-family\s*=\s*)(["'])(.*?)\2""")
-def parse_lock(lock_path: Path) -> dict[str, dict[str, str]]:
- """Return {section_name: {key: value}} parsed from spec_lock.md.
-
- The format is:
- ## section
- - key: value
- """
- sections: dict[str, dict[str, str]] = {}
- current: str | None = None
- for raw in lock_path.read_text(encoding="utf-8").splitlines():
- line = raw.rstrip()
- if line.startswith("## "):
- current = line[3:].strip()
- sections.setdefault(current, {})
- continue
- if current is None:
- continue
- m = re.match(r"^-\s+([A-Za-z0-9_]+)\s*:\s*(.+?)\s*$", line)
- if m:
- sections[current][m.group(1)] = m.group(2)
- return sections
-
-
def rewrite_lock(lock_path: Path, section: str, key: str, new_value: str) -> None:
"""Rewrite the single `- key: old_value` line under `## section`."""
lines = lock_path.read_text(encoding="utf-8").splitlines(keepends=True)