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

feat(ppt): support EMF assets in PPT markdown export

hugohe3958e30493829
diff --git a/skills/ppt-master/scripts/analyze_images.py b/skills/ppt-master/scripts/analyze_images.py
index 40491f1c..83b0f837 100644
--- a/skills/ppt-master/scripts/analyze_images.py
+++ b/skills/ppt-master/scripts/analyze_images.py
@@ -61,7 +61,7 @@ LAYOUT_GAP = 20
MIN_TEXT_HEIGHT = 150
MIN_TEXT_WIDTH = 280
-ImageAnalysis = dict[str, str | float | int]
+ImageAnalysis = dict[str, object]
def _load_image_manifest(images_dir: str) -> dict[str, dict]:
@@ -119,6 +119,52 @@ def _manifest_display_size(meta: dict, ratio: float) -> tuple[int, int]:
return width, height
+def _manifest_usage_count(meta: dict | None) -> int:
+ """Return how many source occurrences point to one asset."""
+ if not meta:
+ return 1
+ usage_count = meta.get("usage_count")
+ if isinstance(usage_count, int) and usage_count > 0:
+ return usage_count
+ occurrences = meta.get("occurrences")
+ if isinstance(occurrences, list) and occurrences:
+ return len(occurrences)
+ return 1
+
+
+def _manifest_ratio_variants(meta: dict | None) -> str:
+ """Return a compact list of display ratio variants from manifest metadata."""
+ if not meta:
+ return ""
+ variants = meta.get("display_ratio_variants")
+ if not isinstance(variants, list):
+ return ""
+ ratios = [
+ f"{float(value):.2f}"
+ for value in variants
+ if isinstance(value, (int, float)) and value > 0
+ ]
+ return ";".join(ratios)
+
+
+def _apply_manifest_metadata(result: ImageAnalysis, meta: dict | None) -> None:
+ """Copy optional manifest fields into an image analysis row."""
+ result["usage_count"] = _manifest_usage_count(meta)
+ result["display_ratio_variants"] = _manifest_ratio_variants(meta)
+ if not meta:
+ return
+
+ source_ext = meta.get("source_ext")
+ original_filename = meta.get("original_filename")
+ if isinstance(source_ext, str):
+ result["source_ext"] = source_ext
+ if isinstance(original_filename, str):
+ result["original_filename"] = original_filename
+ result["asset_kind"] = meta.get("asset_kind", "bitmap")
+ result["svg_renderable"] = meta.get("svg_renderable", True)
+ result["pptx_native_supported"] = meta.get("pptx_native_supported", True)
+
+
def _result_from_manifest(
filename: str,
filepath: str,
@@ -139,15 +185,7 @@ def _result_from_manifest(
'layout_hint': classify_ratio(ratio),
'filesize_kb': os.path.getsize(filepath) / 1024,
}
- source_ext = meta.get("source_ext")
- original_filename = meta.get("original_filename")
- if isinstance(source_ext, str):
- result["source_ext"] = source_ext
- if isinstance(original_filename, str):
- result["original_filename"] = original_filename
- result["asset_kind"] = meta.get("asset_kind", "bitmap")
- result["svg_renderable"] = meta.get("svg_renderable", True)
- result["pptx_native_supported"] = meta.get("pptx_native_supported", True)
+ _apply_manifest_metadata(result, meta)
return result
@@ -279,16 +317,7 @@ def analyze_images(images_dir: str) -> list[ImageAnalysis]:
'layout_hint': layout_hint,
'filesize_kb': os.path.getsize(filepath) / 1024
}
- if meta:
- source_ext = meta.get("source_ext")
- original_filename = meta.get("original_filename")
- if isinstance(source_ext, str):
- result["source_ext"] = source_ext
- if isinstance(original_filename, str):
- result["original_filename"] = original_filename
- result["asset_kind"] = meta.get("asset_kind", "bitmap")
- result["svg_renderable"] = meta.get("svg_renderable", True)
- result["pptx_native_supported"] = meta.get("pptx_native_supported", True)
+ _apply_manifest_metadata(result, meta)
results.append(result)
seen_filenames.add(filename)
except Exception as e:
@@ -345,14 +374,15 @@ def print_results(results: list[ImageAnalysis]) -> None:
print("\nNote: 'Img (SxS)' shows the image area *if* the Strategist chooses the")
print("side-by-side intent for this image. Decide narrative intent first — see")
print("references/strategist.md §h. Hero / atmosphere / accent intents ignore it.\n")
- print(f"{'No.':<4} {'Width':<7} {'Height':<7} {'Ratio':<7} {'Source':<8} {'Size':<10} {'Category':<20} {'Img (SxS)':<14} {'Filename'}")
+ print(f"{'No.':<4} {'Width':<7} {'Height':<7} {'Ratio':<7} {'Source':<8} {'Refs':<5} {'Size':<10} {'Category':<20} {'Img (SxS)':<14} {'Filename'}")
else:
- print(f"\n{'No.':<4} {'Width':<7} {'Height':<7} {'Ratio':<7} {'Source':<8} {'Size':<10} {'Category':<20} {'Filename'}")
+ print(f"\n{'No.':<4} {'Width':<7} {'Height':<7} {'Ratio':<7} {'Source':<8} {'Refs':<5} {'Size':<10} {'Category':<20} {'Filename'}")
print("-" * REPORT_WIDTH)
for i, img in enumerate(results, 1):
ratio_source = str(img.get('ratio_source', 'pixel'))
- base = f"{i:<4} {img['width']:<7} {img['height']:<7} {img['aspect_ratio']:<7.2f} {ratio_source:<8} {img['filesize_kb']:<10.1f}KB {img['layout_hint']:<20}"
+ usage_count = int(img.get('usage_count', 1))
+ base = f"{i:<4} {img['width']:<7} {img['height']:<7} {img['aspect_ratio']:<7.2f} {ratio_source:<8} {usage_count:<5} {img['filesize_kb']:<10.1f}KB {img['layout_hint']:<20}"
if has_layout:
img_area = f"{img['image_w']}x{img['image_h']}"
print(f"{base} {img_area:<14} {img['filename'][:35]}")
@@ -445,9 +475,9 @@ def generate_markdown(results: list[ImageAnalysis], canvas_key: str) -> None:
if has_layout:
img_area = f"{img['image_w']}x{img['image_h']}"
text_area = f"{img['text_w']}x{img['text_h']}"
- print(f"| {img['filename']} | {img['width']}x{img['height']} | {ratio_str} | {img['layout_hint']} | {img_area} | {text_area} | (to be filled) | (to be filled) | {image_type} | {status} | - |")
+ print(f"| {img['filename']} | {img['width']}x{img['height']} | {ratio_str} | {img['layout_hint']} | {img_area} | {text_area} | (to be filled) | {img.get('usage_count', 1)} refs | {image_type} | {status} | - |")
else:
- print(f"| {img['filename']} | {img['width']}x{img['height']} | {ratio_str} | {img['layout_hint']} | (to be filled) | (to be filled) | {image_type} | {status} | - |")
+ print(f"| {img['filename']} | {img['width']}x{img['height']} | {ratio_str} | {img['layout_hint']} | (to be filled) | {img.get('usage_count', 1)} refs | {image_type} | {status} | - |")
print("\n" + "=" * REPORT_WIDTH + "\n")
@@ -461,13 +491,13 @@ def save_csv(results: list[ImageAnalysis], csv_path: str) -> None:
# does not prescribe a layout.
with open(csv_path, 'w', encoding='utf-8') as f:
if has_layout:
- f.write("No,Filename,Width,Height,AspectRatio,PixelAspectRatio,RatioSource,AssetKind,SvgRenderable,PptxNativeSupported,SizeKB,Category,ImageArea_SxS,TextArea_SxS\n")
+ f.write("No,Filename,Width,Height,AspectRatio,PixelAspectRatio,RatioSource,UsageCount,DisplayRatioVariants,AssetKind,SvgRenderable,PptxNativeSupported,SizeKB,Category,ImageArea_SxS,TextArea_SxS\n")
for i, img in enumerate(results, 1):
- f.write(f"{i},{img['filename']},{img['width']},{img['height']},{img['aspect_ratio']:.2f},{img.get('pixel_aspect_ratio', img['aspect_ratio']):.2f},{img.get('ratio_source', 'pixel')},{img.get('asset_kind', 'bitmap')},{img.get('svg_renderable', True)},{img.get('pptx_native_supported', True)},{img['filesize_kb']:.1f},{img['layout_hint']},{img['image_w']}x{img['image_h']},{img['text_w']}x{img['text_h']}\n")
+ f.write(f"{i},{img['filename']},{img['width']},{img['height']},{img['aspect_ratio']:.2f},{img.get('pixel_aspect_ratio', img['aspect_ratio']):.2f},{img.get('ratio_source', 'pixel')},{img.get('usage_count', 1)},{img.get('display_ratio_variants', '')},{img.get('asset_kind', 'bitmap')},{img.get('svg_renderable', True)},{img.get('pptx_native_supported', True)},{img['filesize_kb']:.1f},{img['layout_hint']},{img['image_w']}x{img['image_h']},{img['text_w']}x{img['text_h']}\n")
else:
- f.write("No,Filename,Width,Height,AspectRatio,PixelAspectRatio,RatioSource,AssetKind,SvgRenderable,PptxNativeSupported,SizeKB,Category\n")
+ f.write("No,Filename,Width,Height,AspectRatio,PixelAspectRatio,RatioSource,UsageCount,DisplayRatioVariants,AssetKind,SvgRenderable,PptxNativeSupported,SizeKB,Category\n")
for i, img in enumerate(results, 1):
- f.write(f"{i},{img['filename']},{img['width']},{img['height']},{img['aspect_ratio']:.2f},{img.get('pixel_aspect_ratio', img['aspect_ratio']):.2f},{img.get('ratio_source', 'pixel')},{img.get('asset_kind', 'bitmap')},{img.get('svg_renderable', True)},{img.get('pptx_native_supported', True)},{img['filesize_kb']:.1f},{img['layout_hint']}\n")
+ f.write(f"{i},{img['filename']},{img['width']},{img['height']},{img['aspect_ratio']:.2f},{img.get('pixel_aspect_ratio', img['aspect_ratio']):.2f},{img.get('ratio_source', 'pixel')},{img.get('usage_count', 1)},{img.get('display_ratio_variants', '')},{img.get('asset_kind', 'bitmap')},{img.get('svg_renderable', True)},{img.get('pptx_native_supported', True)},{img['filesize_kb']:.1f},{img['layout_hint']}\n")
print(f"\nCSV saved to: {csv_path}")
diff --git a/skills/ppt-master/scripts/source_to_md/ppt_to_md.py b/skills/ppt-master/scripts/source_to_md/ppt_to_md.py
index 6a8cddd2..75a8c9af 100644
--- a/skills/ppt-master/scripts/source_to_md/ppt_to_md.py
+++ b/skills/ppt-master/scripts/source_to_md/ppt_to_md.py
@@ -14,13 +14,34 @@ Dependency:
from __future__ import annotations
import argparse
+import hashlib
+import json
import re
+import shutil
import sys
from dataclasses import dataclass
+from io import BytesIO
from pathlib import Path
from pptx import Presentation
from pptx.enum.shapes import MSO_SHAPE_TYPE
+from pptx.oxml.ns import qn
+
+
+EMU_PER_INCH = 914400
+OFFICE_VECTOR_EXTENSIONS = {"emf", "wmf"}
+IMAGE_EXT_BY_CONTENT_TYPE = {
+ "image/bmp": "bmp",
+ "image/gif": "gif",
+ "image/jpeg": "jpg",
+ "image/jpg": "jpg",
+ "image/png": "png",
+ "image/svg+xml": "svg",
+ "image/tiff": "tiff",
+ "image/x-emf": "emf",
+ "image/x-wmf": "wmf",
+}
+LEGACY_GENERATED_IMAGE_RE = re.compile(r"^slide_\d{2}_image_\d{2}\.[A-Za-z0-9]+$")
SUPPORTED_FORMATS = {
@@ -42,6 +63,15 @@ class LeafShape:
left: int
+@dataclass
+class SavedPicture:
+ """Extracted image asset plus manifest metadata."""
+
+ filename: str
+ manifest_entry: dict[str, object]
+ is_new_asset: bool
+
+
def normalize_text(value: str) -> str:
"""Collapse whitespace while preserving paragraph boundaries elsewhere."""
value = value.replace("\r\n", "\n").replace("\r", "\n")
@@ -50,6 +80,24 @@ def normalize_text(value: str) -> str:
return "\n".join(lines)
+def normalize_ext(ext: str | None, content_type: str | None = None) -> str:
+ """Return a lowercase extension without a leading dot."""
+ if ext:
+ ext = ext.lower().lstrip(".")
+ if ext == "jpeg":
+ return "jpg"
+ return ext
+ if content_type:
+ return IMAGE_EXT_BY_CONTENT_TYPE.get(content_type.lower(), "bin")
+ return "bin"
+
+
+def sanitize_filename(value: str) -> str:
+ """Return a filesystem-safe basename."""
+ value = re.sub(r"[^\w.\-]+", "_", value, flags=re.UNICODE)
+ return value.strip("._") or "asset"
+
+
def escape_table_cell(value: str) -> str:
"""Escape Markdown table syntax inside a cell."""
return normalize_text(value).replace("|", r"\|") or " "
@@ -127,18 +175,237 @@ def table_to_markdown(table: object) -> str:
return "\n".join(lines)
-def save_picture(shape: object, asset_dir: Path, slide_index: int, image_index: int) -> str | None:
- """Persist a picture shape to the output asset directory."""
+def _image_part_for_shape(shape: object) -> object | None:
+ """Return the first embedded image part referenced by a shape."""
+ element = getattr(shape, "element", None)
+ part = getattr(shape, "part", None)
+ if element is None or part is None:
+ return None
+
try:
- image = shape.image
+ blips = element.xpath(".//a:blip")
except Exception:
return None
- ext = (image.ext or "png").lower()
- filename = f"slide_{slide_index:02d}_image_{image_index:02d}.{ext}"
+ for blip in blips:
+ rel_id = blip.get(qn("r:embed")) or blip.get(qn("r:link"))
+ if not rel_id:
+ continue
+ try:
+ return part.related_part(rel_id)
+ except Exception:
+ continue
+ return None
+
+
+def _image_size_from_bytes(blob: bytes) -> tuple[int | None, int | None]:
+ """Return bitmap dimensions when Pillow can decode the bytes."""
+ try:
+ from PIL import Image
+ except ImportError:
+ return None, None
+ try:
+ with Image.open(BytesIO(blob)) as img:
+ return img.width, img.height
+ except (OSError, ValueError):
+ return None, None
+
+
+def _shape_emu(shape: object, attr: str) -> int:
+ value = getattr(shape, attr, 0) or 0
+ return int(value)
+
+
+def _shape_occurrence(
+ shape: object,
+ slide_index: int,
+) -> dict[str, object]:
+ """Return slide-specific image placement metadata."""
+ display_width_emu = _shape_emu(shape, "width")
+ display_height_emu = _shape_emu(shape, "height")
+ display_ratio = (
+ display_width_emu / display_height_emu
+ if display_width_emu > 0 and display_height_emu > 0
+ else None
+ )
+ return {
+ "slide_index": slide_index,
+ "shape_name": str(getattr(shape, "name", "")),
+ "display_left_emu": _shape_emu(shape, "left"),
+ "display_top_emu": _shape_emu(shape, "top"),
+ "display_width_emu": display_width_emu,
+ "display_height_emu": display_height_emu,
+ "display_width_in": round(display_width_emu / EMU_PER_INCH, 4) if display_width_emu else None,
+ "display_height_in": round(display_height_emu / EMU_PER_INCH, 4) if display_height_emu else None,
+ "display_ratio": round(display_ratio, 6) if display_ratio else None,
+ }
+
+
+def _update_manifest_usage(entry: dict[str, object]) -> None:
+ """Refresh aggregate fields after adding an occurrence."""
+ occurrences = entry.get("occurrences")
+ if not isinstance(occurrences, list):
+ occurrences = []
+ entry["usage_count"] = len(occurrences)
+ ratios = sorted({
+ occurrence.get("display_ratio")
+ for occurrence in occurrences
+ if isinstance(occurrence, dict)
+ and isinstance(occurrence.get("display_ratio"), (int, float))
+ })
+ if ratios:
+ entry["display_ratio_variants"] = ratios
+ if entry.get("display_ratio") is None:
+ entry["display_ratio"] = ratios[0]
+
+
+def _manifest_entry(
+ *,
+ index: int,
+ filename: str,
+ image_part: object,
+ ext: str,
+ blob: bytes,
+ occurrence: dict[str, object],
+) -> dict[str, object]:
+ """Build image_manifest.json metadata for one unique PowerPoint media part."""
+ pixel_width, pixel_height = _image_size_from_bytes(blob)
+ pixel_ratio = (
+ pixel_width / pixel_height
+ if pixel_width and pixel_height
+ else None
+ )
+ is_office_vector = ext in OFFICE_VECTOR_EXTENSIONS
+ partname = str(getattr(image_part, "partname", ""))
+ content_type = str(getattr(image_part, "content_type", ""))
+
+ entry: dict[str, object] = {
+ "index": index,
+ "filename": filename,
+ "original_filename": filename,
+ "asset_kind": "office_vector" if is_office_vector else "bitmap",
+ "svg_renderable": not is_office_vector,
+ "pptx_native_supported": True,
+ "source_kind": "pptx_picture",
+ "source_ext": f".{ext}",
+ "source_target": partname.lstrip("/"),
+ "content_type": content_type,
+ "display_left_emu": occurrence.get("display_left_emu"),
+ "display_top_emu": occurrence.get("display_top_emu"),
+ "display_width_emu": occurrence.get("display_width_emu"),
+ "display_height_emu": occurrence.get("display_height_emu"),
+ "display_width_in": occurrence.get("display_width_in"),
+ "display_height_in": occurrence.get("display_height_in"),
+ "display_ratio": occurrence.get("display_ratio"),
+ "pixel_width": pixel_width,
+ "pixel_height": pixel_height,
+ "pixel_ratio": round(pixel_ratio, 6) if pixel_ratio else None,
+ "occurrences": [occurrence],
+ }
+ if entry["display_ratio"] is None and pixel_ratio:
+ entry["display_ratio"] = round(pixel_ratio, 6)
+ _update_manifest_usage(entry)
+ return entry
+
+
+def _asset_cache_key(image_part: object, blob: bytes) -> str:
+ """Return a stable key for deduplicating repeated PPTX media references."""
+ partname = str(getattr(image_part, "partname", ""))
+ if partname:
+ return partname
+ return hashlib.sha256(blob).hexdigest()
+
+
+def _asset_filename(
+ image_part: object,
+ ext: str,
+ asset_index: int,
+ used_filenames: set[str],
+) -> str:
+ """Return a unique asset filename, preferring the PPTX media basename."""
+ partname = str(getattr(image_part, "partname", ""))
+ base = sanitize_filename(Path(partname).name) if partname else f"image_{asset_index:03d}.{ext}"
+ if "." not in base:
+ base = f"{base}.{ext}"
+ if base not in used_filenames:
+ used_filenames.add(base)
+ return base
+
+ path = Path(base)
+ stem = path.stem
+ suffix = path.suffix or f".{ext}"
+ counter = 2
+ while True:
+ candidate = f"{stem}_{counter}{suffix}"
+ if candidate not in used_filenames:
+ used_filenames.add(candidate)
+ return candidate
+ counter += 1
+
+
+def save_picture(
+ shape: object,
+ asset_dir: Path,
+ slide_index: int,
+ asset_index: int,
+ asset_cache: dict[str, SavedPicture],
+ used_filenames: set[str],
+) -> SavedPicture | None:
+ """Persist a shape image to the output asset directory."""
+ image_part = _image_part_for_shape(shape)
+ if image_part is None:
+ return None
+
+ content_type = getattr(image_part, "content_type", None)
+ part_ext = getattr(getattr(image_part, "partname", None), "ext", None)
+ ext = normalize_ext(part_ext, content_type)
+ blob = bytes(getattr(image_part, "blob", b""))
+ if not blob:
+ return None
+
+ occurrence = _shape_occurrence(shape, slide_index)
+ cache_key = _asset_cache_key(image_part, blob)
+ cached = asset_cache.get(cache_key)
+ if cached is not None:
+ occurrences = cached.manifest_entry.setdefault("occurrences", [])
+ if isinstance(occurrences, list):
+ occurrences.append(occurrence)
+ _update_manifest_usage(cached.manifest_entry)
+ return SavedPicture(
+ filename=cached.filename,
+ manifest_entry=cached.manifest_entry,
+ is_new_asset=False,
+ )
+
+ filename = _asset_filename(image_part, ext, asset_index, used_filenames)
output_path = asset_dir / filename
- output_path.write_bytes(image.blob)
- return filename
+ output_path.write_bytes(blob)
+ saved = SavedPicture(
+ filename=filename,
+ manifest_entry=_manifest_entry(
+ index=asset_index,
+ filename=filename,
+ image_part=image_part,
+ ext=ext,
+ blob=blob,
+ occurrence=occurrence,
+ ),
+ is_new_asset=True,
+ )
+ asset_cache[cache_key] = saved
+ return saved
+
+
+def _reset_generated_asset_dir(asset_dir: Path) -> None:
+ """Remove a previously generated asset directory."""
+ if not asset_dir.exists():
+ return
+ if not (asset_dir / "image_manifest.json").is_file():
+ for path in asset_dir.iterdir():
+ if path.is_file() and LEGACY_GENERATED_IMAGE_RE.match(path.name):
+ path.unlink()
+ return
+ shutil.rmtree(asset_dir)
def extract_notes(slide: object) -> str:
@@ -187,6 +454,7 @@ def convert_presentation_to_markdown(
out_file.parent.mkdir(parents=True, exist_ok=True)
asset_dir = out_file.parent / f"{out_file.stem}_files"
+ _reset_generated_asset_dir(asset_dir)
presentation = Presentation(str(input_file))
lines = [
@@ -198,7 +466,11 @@ def convert_presentation_to_markdown(
]
image_count = 0
+ image_ref_count = 0
asset_dir_used = False
+ image_manifest: list[dict[str, object]] = []
+ asset_cache: dict[str, SavedPicture] = {}
+ used_filenames: set[str] = set()
for slide_index, slide in enumerate(presentation.slides, 1):
lines.append(f"## Slide {slide_index}")
@@ -214,24 +486,44 @@ def convert_presentation_to_markdown(
blocks.append(table_md)
continue
- if shape.shape_type == MSO_SHAPE_TYPE.PICTURE:
+ is_picture_shape = shape.shape_type in {
+ MSO_SHAPE_TYPE.PICTURE,
+ MSO_SHAPE_TYPE.LINKED_PICTURE,
+ }
+ has_shape_image = is_picture_shape or _image_part_for_shape(shape) is not None
+ if has_shape_image:
+ image_ref_count += 1
next_image_index = image_count + 1
asset_dir.mkdir(parents=True, exist_ok=True)
- filename = save_picture(shape, asset_dir, slide_index, next_image_index)
- if filename is None:
- blocks.append(f"> [Image] {getattr(shape, 'name', 'Picture')}")
- continue
-
- image_count = next_image_index
- asset_dir_used = True
- blocks.append(f"![Slide {slide_index} Image {image_count}]({asset_dir.name}/{filename})")
- continue
+ saved_picture = save_picture(
+ shape,
+ asset_dir,
+ slide_index,
+ next_image_index,
+ asset_cache,
+ used_filenames,
+ )
+ if saved_picture is None:
+ if is_picture_shape:
+ blocks.append(f"> [Image] {getattr(shape, 'name', 'Picture')}")
+ continue
+ else:
+ if saved_picture.is_new_asset:
+ image_count = next_image_index
+ image_manifest.append(saved_picture.manifest_entry)
+ asset_dir_used = True
+ blocks.append(
+ f"![Slide {slide_index} Image {image_ref_count}]"
+ f"({asset_dir.name}/{saved_picture.filename})"
+ )
+ if is_picture_shape:
+ continue
if getattr(shape, "has_text_frame", False):
text_md = text_frame_to_markdown(shape.text_frame)
if text_md:
blocks.append(text_md)
- continue
+ continue
if getattr(shape, "has_chart", False):
blocks.append(f"> [Chart] {getattr(shape, 'name', 'Chart')}")
@@ -252,11 +544,25 @@ def convert_presentation_to_markdown(
markdown_content = "\n".join(lines).strip() + "\n"
out_file.write_text(markdown_content, encoding="utf-8")
+ if image_manifest:
+ (asset_dir / "image_manifest.json").write_text(
+ json.dumps(image_manifest, ensure_ascii=False, indent=2) + "\n",
+ encoding="utf-8",
+ )
print(f"[OK] Saved Markdown to: {out_file}")
if asset_dir_used:
- media_files = [path for path in asset_dir.iterdir() if path.is_file()]
+ media_files = [
+ path for path in asset_dir.iterdir()
+ if path.is_file() and path.name != "image_manifest.json"
+ ]
print(f" Extracted {len(media_files)} image file(s) -> {asset_dir}")
+ if image_ref_count != len(media_files):
+ print(
+ f" Deduplicated {image_ref_count} image reference(s) "
+ f"into {len(media_files)} asset file(s)"
+ )
+ print(f" Wrote image manifest -> {asset_dir / 'image_manifest.json'}")
return markdown_content