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(source-to-md): keep same-stem outputs distinct in direct-backend batches (#317)

hugohe38d630fffe2ac
diff --git a/skills/ppt-master/scripts/docs/conversion.md b/skills/ppt-master/scripts/docs/conversion.md
index 6dacba58..5580cab5 100644
--- a/skills/ppt-master/scripts/docs/conversion.md
+++ b/skills/ppt-master/scripts/docs/conversion.md
@@ -24,6 +24,14 @@ unified `source_to_md.py` dispatcher writes a missing profile before success.
| Image manifest | `<stem>_files/image_manifest.json` when image metadata is available |
| Conversion profile | `<stem>.conversion_profile.json` beside the Markdown output when written |
+For multi-file or directory inputs, the unified entry and direct PDF, document,
+Excel, and PowerPoint backends allocate distinct Markdown paths within the run.
+Without `-o`, each output stays in its source's directory; with `-o`, outputs
+share that directory. Collisions with inputs or other planned outputs gain
+`_2`, `_3`, etc., reported as `[INFO] Renamed output ...` on stderr. Assets and
+profiles follow the chosen Markdown stem. Separate runs retain the existing
+overwrite behavior for unrelated outputs.
+
When present, the conversion profile is metadata only: converter, source path,
Markdown structure counts, asset directory, image manifest path, and image
count. Downstream PPT workflows still use Markdown and the image manifest as
@@ -155,9 +163,10 @@ pip install mammoth markdownify ebooklib nbconvert beautifulsoup4
# Windows: https://pandoc.org/installing.html
```
-All paths produce `<input>.md`. Extracted assets use a sibling `<input>_files/`
+By default, each input produces `<input-stem>.md`, subject to batch collision
+renaming. Extracted assets use a sibling `<output-stem>_files/`
directory with relative references. Without assets, that directory need not remain.
-The direct backend then attempts `<input>.conversion_profile.json` under the
+The direct backend then attempts `<output-stem>.conversion_profile.json` under the
shared best-effort sidecar contract.
## `source_to_md/excel_to_md.py`
diff --git a/skills/ppt-master/scripts/source_to_md/_batch.py b/skills/ppt-master/scripts/source_to_md/_batch.py
index ef98a09f..11179c12 100644
--- a/skills/ppt-master/scripts/source_to_md/_batch.py
+++ b/skills/ppt-master/scripts/source_to_md/_batch.py
@@ -84,8 +84,16 @@ def _output_for(
batch_mode: bool,
used_outputs: set[Path],
) -> Path:
- if output_arg and batch_mode:
- return unique_output_path(Path(output_arg), source.stem, used_outputs)
+ if batch_mode:
+ output_dir = Path(output_arg) if output_arg else source.parent
+ default_output = output_dir / f"{source.stem}.md"
+ output = unique_output_path(output_dir, source.stem, used_outputs)
+ if output != default_output:
+ _print_status(
+ f"[INFO] Renamed output for {source}: {default_output} -> {output} "
+ "(input/output collision)"
+ )
+ return output
if output_arg:
return Path(output_arg)
return source.with_suffix(".md")
@@ -115,7 +123,7 @@ def run_path_batch(
success_count = 0
failed: list[str] = []
skipped: list[str] = list(expansion_errors)
- used_outputs: set[Path] = set()
+ used_outputs = {source.resolve() for source in sources}
for source in sources:
output = _output_for(source, output_arg, batch_mode, used_outputs)
diff --git a/skills/ppt-master/scripts/tests/test_source_to_md_cli.py b/skills/ppt-master/scripts/tests/test_source_to_md_cli.py
index ee4924c3..d67e103c 100644
--- a/skills/ppt-master/scripts/tests/test_source_to_md_cli.py
+++ b/skills/ppt-master/scripts/tests/test_source_to_md_cli.py
@@ -271,6 +271,73 @@ class SourceCollisionTests(unittest.TestCase):
for line in result.stdout.splitlines() if line.startswith("{")
]
+ def test_direct_pdf_batch_preserves_inputs_and_reports_renames(self) -> None:
+ try:
+ import fitz
+ except ImportError:
+ self.skipTest("PyMuPDF unavailable")
+ for reverse in (False, True):
+ for separate_output in (False, True):
+ with self.subTest(reverse=reverse, output=separate_output):
+ root = self.root / f"pdf_{reverse}_{separate_output}"
+ root.mkdir()
+ sources = [root / "same.pdf", root / "same.md", root / "same_2.md"]
+ originals = {}
+ for index, source in enumerate(sources):
+ with fitz.open() as document:
+ page = document.new_page()
+ page.insert_text((72, 150), f"PDF-SOURCE-{index}")
+ originals[source] = document.tobytes()
+ source.write_bytes(originals[source])
+ if reverse:
+ sources.reverse()
+ arguments = [str(path) for path in sources]
+ if separate_output:
+ arguments += ["-o", str(root)]
+ result = subprocess.run(
+ [sys.executable, str(WEB_BACKEND_DIR / "pdf_to_md.py"),
+ *arguments, "--images", "none"],
+ capture_output=True, text=True, encoding="utf-8", check=False,
+ )
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ for source, content in originals.items():
+ self.assertEqual(source.read_bytes(), content)
+ profiles = sorted(root.glob("*.conversion_profile.json"))
+ self.assertEqual(len(profiles), 3)
+ for path in profiles:
+ profile = json.loads(path.read_text(encoding="utf-8"))
+ source = root / profile["source"]["name"]
+ output = root / profile["outputs"]["markdown"]
+ self.assertNotIn(output, sources)
+ self.assertIn(
+ f"[INFO] Renamed output for {source}: {source.with_suffix('.md')} "
+ f"-> {output} (input/output collision)", result.stderr,
+ )
+
+ def test_direct_batch_keeps_outputs_in_each_source_directory(self) -> None:
+ from openpyxl import Workbook
+
+ sources = []
+ for name in ("first", "second"):
+ directory = self.root / name
+ directory.mkdir()
+ source = directory / "same.xlsx"
+ workbook = Workbook()
+ workbook.active.append([name])
+ workbook.save(source)
+ workbook.close()
+ sources.append(source)
+ for _ in range(2):
+ result = subprocess.run(
+ [sys.executable, str(WEB_BACKEND_DIR / "excel_to_md.py"), *map(str, sources)],
+ capture_output=True, text=True, encoding="utf-8", check=False,
+ )
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertNotIn("Renamed output", result.stderr)
+ for source in sources:
+ self.assertEqual(list(source.parent.glob("*.md")), [source.with_suffix(".md")])
+ self.assertIn(source.parent.name, source.with_suffix(".md").read_text(encoding="utf-8"))
+
def test_same_stem_batch_preserves_markdown_in_both_orders(self) -> None:
for reverse in (False, True):
for output_directory in (False, True):
diff --git a/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_excel.py b/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_excel.py
index 0465b028..5c6b3460 100644
--- a/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_excel.py
+++ b/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_excel.py
@@ -24,6 +24,49 @@ import excel_to_md # noqa: E402
class ExcelContentLossTests(unittest.TestCase):
+ def test_same_stem_batch_preserves_each_workbook_and_profile(self) -> None:
+ for directory_input in (False, True):
+ for separate_output in (False, True):
+ with self.subTest(directory=directory_input, output=separate_output):
+ with tempfile.TemporaryDirectory() as tmp:
+ root = Path(tmp)
+ sources = []
+ totals = {"budget.xlsx": 20000, "budget.xlsm": 22500}
+ for name, total in totals.items():
+ workbook = Workbook()
+ workbook.active.append(["Category", "Amount"])
+ workbook.active.append(["Total", total])
+ source = root / name
+ workbook.save(source)
+ workbook.close()
+ sources.append(source)
+ output = root / "output" if separate_output else root
+ arguments = [root] if directory_input else sources
+ if separate_output:
+ arguments += ["-o", output]
+ result = subprocess.run(
+ [sys.executable, str(SCRIPTS_DIR / "source_to_md/excel_to_md.py"),
+ *map(str, arguments)],
+ capture_output=True, text=True, encoding="utf-8", check=False,
+ )
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertIn("Success: 2/2, Failed: 0", result.stderr)
+ self.assertIn("[INFO] Renamed output for", result.stderr)
+ self.assertEqual(sorted(p.name for p in output.glob("*.md")),
+ ["budget.md", "budget_2.md"])
+ profiles = sorted(output.glob("*.conversion_profile.json"))
+ self.assertEqual(len(profiles), 2)
+ seen = set()
+ for path in profiles:
+ profile = json.loads(path.read_text(encoding="utf-8"))
+ source_name = profile["source"]["name"]
+ seen.add(source_name)
+ markdown = output / profile["outputs"]["markdown"]
+ self.assertIn(f"| Total | {totals[source_name]} |",
+ markdown.read_text(encoding="utf-8"))
+ self.assertEqual(path, markdown.with_suffix(".conversion_profile.json"))
+ self.assertEqual(seen, set(totals))
+
def _convert(self, workbook, **options):
with tempfile.TemporaryDirectory() as tmp:
source = Path(tmp) / "book.xlsx"