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(web-to-md): same-title pages in one batch get distinct outputs

hugohe3e847939c073d
diff --git a/skills/ppt-master/scripts/source_to_md/web_to_md.py b/skills/ppt-master/scripts/source_to_md/web_to_md.py
index 39349556..a0e173dd 100644
--- a/skills/ppt-master/scripts/source_to_md/web_to_md.py
+++ b/skills/ppt-master/scripts/source_to_md/web_to_md.py
@@ -57,6 +57,7 @@ if str(_SCRIPTS_DIR) not in sys.path:
sys.path.insert(0, str(_SCRIPTS_DIR))
from console_encoding import configure_utf8_stdio # noqa: E402
+from _batch import unique_output_path # noqa: E402
from _dispatcher import ( # noqa: E402
DOC_SUFFIXES,
EXCEL_SUFFIXES,
@@ -1383,6 +1384,10 @@ def _meta_refresh_target(soup: BeautifulSoup, base_url: str) -> str | None:
return target if urlparse(target).scheme in {"http", "https"} else None
+# Auto-named outputs claimed in this run; explicit -o paths are not tracked.
+_AUTO_NAMED_OUTPUTS: set[Path] = set()
+
+
def process_url(
url: str,
output_file: str | None = None,
@@ -1431,8 +1436,14 @@ def process_url(
output_path = output_file
else:
base_name = derive_base_name(metadata['title'], url)
- filename = f"{base_name}.md"
- output_path = os.path.join(CONFIG["output_dir"], filename)
+ default_path = os.path.join(CONFIG["output_dir"], f"{base_name}.md")
+ # Two pages titled "Report" in one batch used to share Report.md.
+ output_path = str(unique_output_path(
+ Path(CONFIG["output_dir"]), base_name, _AUTO_NAMED_OUTPUTS,
+ ))
+ if output_path != default_path:
+ print(f" [INFO] Renamed output for {url}: {default_path} -> {output_path} "
+ "(title collision)")
output_dirname = os.path.dirname(output_path) or "."
os.makedirs(output_dirname, exist_ok=True)
diff --git a/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_web.py b/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_web.py
index 60aecf29..ced5db6b 100644
--- a/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_web.py
+++ b/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_web.py
@@ -111,3 +111,24 @@ class PlainTextDetectionTests(unittest.TestCase):
self.assertFalse(
web_to_md.is_plain_text_document(self.URL, "<!DOCTYPE html><html><body>x</body></html>")
)
+
+
+class SameTitleBatchTests(unittest.TestCase):
+ def test_pages_with_the_same_title_get_distinct_outputs(self) -> None:
+ def response(url: str) -> SimpleNamespace:
+ paragraph = f"BODY-{url[-1]} " + "long paragraph text " * 30
+ html = (f"<html><head><title>Report</title></head><body><article>"
+ f"<h1>Report</h1><p>{paragraph}</p></article></body></html>")
+ return SimpleNamespace(url=url, headers={"Content-Type": "text/html; charset=utf-8"},
+ content=html.encode(), status_code=200)
+
+ with tempfile.TemporaryDirectory() as tmp, \
+ patch.object(web_to_md, "fetch_response", side_effect=response), \
+ redirect_stdout(io.StringIO()):
+ code = web_to_md.main(["https://example.com/A", "https://example.com/B",
+ "--no-images", "-d", tmp])
+ first = (Path(tmp) / "Report.md").read_text(encoding="utf-8")
+ second = (Path(tmp) / "Report_2.md").read_text(encoding="utf-8")
+ self.assertEqual(code, 0)
+ self.assertIn("BODY-A", first)
+ self.assertIn("BODY-B", second)