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: route document URLs to their converter; bullet glyphs never make PDF headings; polygon carries a filter
hugohe30b593d6d803b
diff --git a/skills/ppt-master/scripts/source_to_md/pdf_to_md.py b/skills/ppt-master/scripts/source_to_md/pdf_to_md.pyindex b07eb859..5a705e13 100644--- a/skills/ppt-master/scripts/source_to_md/pdf_to_md.py+++ b/skills/ppt-master/scripts/source_to_md/pdf_to_md.py@@ -132,6 +132,10 @@ def get_heading_level(size: float, size_map: dict, text: str = "",if len(text) > 80:return 0+ # Exclusion: a bullet-led line is a list item, whatever its glyph size+ if text[:1] in _BULLET_GLYPHS:+ return 0+# Exclusion: complete sentences ending with punctuationsentence_endings = '.。!!??'if text and text[-1] in sentence_endings:@@ -184,12 +188,23 @@ def format_span_text(text: str, flags: int) -> str:return text+# Bullet glyphs a PDF sets as their own span; ``·`` (U+00B7) is common in+# fact sheets, and a stray control character often follows the glyph.+_BULLET_GLYPHS = '•●○◦▪▸►·‧∙・'+++def is_bullet_glyph_span(text: str) -> bool:+ """Return whether a span holds only a bullet glyph (plus spaces / control characters)."""+ stripped = re.sub(r'[\s\x00-\x1f]+', '', text)+ return len(stripped) == 1 and stripped in _BULLET_GLYPHS++def detect_list_item(text: str) -> tuple:"""Detect if the text is a list item. Returns (is_list, list_type, content)."""text = text.strip()ul_patterns = [- (r'^[•●○◦▪▸►]\s*', '-'),+ (rf'^[{_BULLET_GLYPHS}][\s\x00-\x1f]*', '-'),(r'^[-–—]\s+', '-'),(r'^\*\s+', '-'),]@@ -1474,6 +1489,12 @@ def extract_pdf_to_markdown(span_size = span["size"]span_flags = span["flags"]+ # A bullet glyph set in its own larger span must not+ # promote the line to a heading; it is a list marker.+ if is_bullet_glyph_span(span_text):+ formatted_spans.append(span_text)+ continue+line_size = max(line_size, span_size)line_flags |= span_flagsspan_count += 1@@ -1503,6 +1524,8 @@ def extract_pdf_to_markdown(heading_level = get_heading_level(line_size, size_map, line_text, line_flags)is_list, list_type, list_content = detect_list_item(line_text)+ if is_list and not list_content.split(' ', 1)[-1].strip():+ continueif heading_level > 0:prefix = '#' * heading_level + ' '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.pyindex 58b76894..2c85e5b8 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@@ -37,6 +37,7 @@ import jsonimport osimport reimport socket+import subprocessimport sysimport timefrom pathlib import Path@@ -47,6 +48,14 @@ 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 _dispatcher import ( # noqa: E402+ DOC_SUFFIXES,+ EXCEL_SUFFIXES,+ LEGACY_EXCEL_SUFFIXES,+ PDF_SUFFIXES,+ PRESENTATION_SUFFIXES,+ build_conversion_command,+)from _conversion_profile import ( # noqa: E402profile_path_for,write_conversion_profile_best_effort,@@ -272,15 +281,8 @@ CONFIG = {}-def fetch_url(url: str) -> tuple[str, str]:- """Fetch a web page with explicit headers and encoding detection.-- Args:- url: Target URL.-- Returns:- The response body as text and the final URL after redirects.- """+def fetch_response(url: str):+ """Fetch a URL with explicit headers and return the raw HTTP response."""headers = {"User-Agent": CONFIG["user_agent"],"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",@@ -291,12 +293,17 @@ def fetch_url(url: str) -> tuple[str, str]:response = _http_get(url, headers=headers,timeout=CONFIG["timeout"], verify=not CONFIG["insecure"])response.raise_for_status()-- return _decode_response_text(response), response.url+ return responseexcept Exception as e:raise Exception(f"Failed to fetch {url}: {str(e)}")+def fetch_url(url: str) -> tuple[str, str]:+ """Fetch a web page as decoded text plus the final URL after redirects."""+ response = fetch_response(url)+ return _decode_response_text(response), response.url++def clean_title(title: str) -> str:"""Remove common site suffixes from a title."""if not title:@@ -955,6 +962,64 @@ def _save_plain_text_document(return True, url, None, output_path+_DOCUMENT_CONTENT_TYPES = {+ "application/pdf": ".pdf",+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx",+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ".xlsx",+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": ".pptx",+ "application/msword": ".doc",+ "application/vnd.ms-excel": ".xls",+ "application/epub+zip": ".epub",+}+_DOCUMENT_URL_SUFFIXES = frozenset(+ PDF_SUFFIXES | EXCEL_SUFFIXES | LEGACY_EXCEL_SUFFIXES | PRESENTATION_SUFFIXES+ | (DOC_SUFFIXES - {".html", ".htm"})+)+++def remote_document_suffix(url: str, content_type: str, head: bytes) -> str | None:+ """Return the file suffix when a fetched URL is a document, not an HTML page.++ A ``.pdf`` URL (or a suffix-less download that answers ``application/pdf``)+ has no HTML body; the HTML extractor would fail on it. The body magic and+ the Content-Type decide first, then the URL suffix, unless the server+ explicitly answered with HTML (a viewer page at a document-looking URL).+ """+ if head.startswith(b"%PDF-"):+ return ".pdf"+ ctype = content_type.split(";")[0].strip().lower()+ if ctype in _DOCUMENT_CONTENT_TYPES:+ return _DOCUMENT_CONTENT_TYPES[ctype]+ if ctype.startswith("text/html") or ctype == "application/xhtml+xml":+ return None+ suffix = os.path.splitext(urlparse(url).path)[1].lower()+ return suffix if suffix in _DOCUMENT_URL_SUFFIXES else None+++def _convert_remote_document(+ url: str, body: bytes, suffix: str, output_file: str | None,+) -> tuple[bool, str, str | None, str | None]:+ """Save a downloaded document beside its Markdown and run its own converter."""+ stem = os.path.splitext(os.path.basename(urlparse(url).path))[0]+ output_path = output_file or os.path.join(+ CONFIG["output_dir"], f"{derive_base_name(stem, url)}.md",+ )+ output_dirname = os.path.dirname(output_path) or "."+ os.makedirs(output_dirname, exist_ok=True)+ base_name = os.path.splitext(os.path.basename(output_path))[0]+ local_path = os.path.join(output_dirname, f"{base_name}{suffix}")+ with open(local_path, "wb") as f:+ f.write(body)+ print(f" [OK] Document: {len(body)} bytes saved to {local_path}")++ route = build_conversion_command(local_path, output_path)+ print(f" [>>] {route.script_name} {local_path}")+ rc = subprocess.run(route.command).returncode+ if rc != 0 or not os.path.isfile(output_path):+ return False, url, f"{route.script_name} exited with {rc}", None+ return True, url, None, output_path++def process_url(url: str,output_file: str | None = None,@@ -969,7 +1034,12 @@ def process_url("""print(f"\n[Fetching] {url}")try:- html, page_url = fetch_url(url)+ response = fetch_response(url)+ suffix = remote_document_suffix(+ url, response.headers.get("Content-Type", ""), response.content[:8])+ if suffix:+ return _convert_remote_document(url, response.content, suffix, output_file)+ html, page_url = _decode_response_text(response), response.urlif is_plain_text_document(url, html):return _save_plain_text_document(url, html, output_file)soup = BeautifulSoup(html, 'html.parser')diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.pyindex 8fa6cece..d25ade5b 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py@@ -1909,6 +1909,14 @@ def convert_polygon(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | Nonefill = build_fill_xml(elem, ctx, fill_op)stroke = build_stroke_xml(elem, ctx, stroke_op)+ effect = ''+ filt_id = get_effective_filter_id(elem, ctx)+ if filt_id and filt_id in ctx.defs:+ effect = build_effect_xml(+ ctx.defs[filt_id],+ get_element_opacity(elem, ctx),+ )+shape_id = _claim_element_shape_id(elem, ctx)xfrm_attr = ''off_x = px_to_emu(min_x)@@ -1931,7 +1939,7 @@ def convert_polygon(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | Nonectx,shape_id, f'Polygon {shape_id}',off_x, off_y, w_emu, h_emu,- geom, fill, stroke, xfrm_attr=xfrm_attr,+ geom, fill, stroke, effect, xfrm_attr=xfrm_attr,),bounds_emu=bounds_emu,)diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.pyindex 05182d47..74d3a72a 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py@@ -263,6 +263,7 @@ PROJECT_FILTER_PUBLIC_TARGETS = frozenset({'circle','image','path',+ 'polygon','text',})_PROJECT_MARKER_NUMBER_TOKEN = (@@ -2821,7 +2822,7 @@ def project_filter_errors(root: ET.Element) -> list[str]:):errors.add(f'{label} cannot use filter; supported native targets are '- 'rect, circle, image, path, text, a validated compact authored-'+ 'rect, circle, image, path, polygon, text, a validated compact authored-''preset shape, and an exact registered carrier group')if tag == 'image' and elem.get('clip-path') is not None:diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.pyindex 7080ec06..a6ca7368 100644--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py@@ -166,6 +166,26 @@ THEME_REL_TYPE = ()THEME_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.theme+xml"PML_NS = "http://schemas.openxmlformats.org/presentationml/2006/main"++# ST_SlideSizeType tokens for the standard screen ratios; every other canvas+# (portrait story, banner, print) is ``custom``. python-pptx's default+# template says ``screen4x3`` whatever cx/cy are set to afterwards.+_SLIDE_SIZE_TYPES = ((4, 3, "screen4x3"), (16, 9, "screen16x9"), (16, 10, "screen16x10"))+++def _slide_size_type(width_emu: int, height_emu: int) -> str:+ """Return the ``p:sldSz type`` token matching a slide size."""+ for ratio_w, ratio_h, token in _SLIDE_SIZE_TYPES:+ if abs(width_emu * ratio_h - height_emu * ratio_w) <= max(width_emu, height_emu) // 200:+ return token+ return "custom"+++def _set_slide_size_type(presentation, width_emu: int, height_emu: int) -> None:+ """Make the ``type`` token agree with the cx/cy the exporter just set."""+ slide_size = presentation.element.find(f"{{{PML_NS}}}sldSz")+ if slide_size is not None:+ slide_size.set("type", _slide_size_type(width_emu, height_emu))DML_NS = "http://schemas.openxmlformats.org/drawingml/2006/main"REL_NS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"P14_NS = "http://schemas.microsoft.com/office/powerpoint/2010/main"@@ -6852,6 +6872,7 @@ def create_pptx_with_native_svg(prs = Presentation()prs.slide_width = width_emuprs.slide_height = height_emu+ _set_slide_size_type(prs, width_emu, height_emu)blank_layout = prs.slide_layouts[6]for _ in svg_files:diff --git a/skills/ppt-master/scripts/tests/test_dogfood_leaves_fixes.py b/skills/ppt-master/scripts/tests/test_dogfood_leaves_fixes.pynew file mode 100644index 00000000..3fa2c7fd--- /dev/null+++ b/skills/ppt-master/scripts/tests/test_dogfood_leaves_fixes.py@@ -0,0 +1,122 @@+#!/usr/bin/env python3+"""Regression tests for the fixes reported by the Why Leaves Turn dogfood run.++Document URLs route to their own converter, bullet glyphs never promote a PDF+line to a heading, ``<polygon>`` carries a filter, and the exported slide size+type token follows the canvas.+"""++from __future__ import annotations++import sys+import tempfile+import unittest+from pathlib import Path+from xml.etree import ElementTree as ET++SCRIPTS_DIR = Path(__file__).resolve().parents[1]+if str(SCRIPTS_DIR) not in sys.path:+ sys.path.insert(0, str(SCRIPTS_DIR))+BACKEND_DIR = SCRIPTS_DIR / "source_to_md"+if str(BACKEND_DIR) not in sys.path:+ sys.path.insert(0, str(BACKEND_DIR))++import pdf_to_md # noqa: E402+import web_to_md # noqa: E402+from svg_to_pptx.drawingml.converter import convert_svg_to_slide_shapes # noqa: E402+from svg_to_pptx.drawingml.utils import project_filter_errors # noqa: E402+from svg_to_pptx.pptx_package.builder import _slide_size_type # noqa: E402++PDF_URL = "https://www.example.gov/content/pkg/report/pdf/report.pdf"+++class RemoteDocumentSuffixTests(unittest.TestCase):+ def test_pdf_url_with_pdf_content_type(self) -> None:+ self.assertEqual(+ web_to_md.remote_document_suffix(PDF_URL, "application/pdf", b"%PDF-1.4"), ".pdf")++ def test_suffixless_download_answering_pdf(self) -> None:+ self.assertEqual(+ web_to_md.remote_document_suffix(+ "https://example.org/download?id=7", "application/pdf; charset=binary", b"%PDF-1.7"),+ ".pdf")++ def test_body_magic_wins_over_wrong_content_type(self) -> None:+ self.assertEqual(+ web_to_md.remote_document_suffix(+ "https://example.org/files/report", "application/octet-stream", b"%PDF-1.7"),+ ".pdf")++ def test_docx_url_by_suffix(self) -> None:+ self.assertEqual(+ web_to_md.remote_document_suffix(+ "https://example.org/a/brief.docx", "application/octet-stream", b"PK\x03\x04"),+ ".docx")++ def test_html_viewer_at_document_url_stays_web(self) -> None:+ self.assertIsNone(+ web_to_md.remote_document_suffix(PDF_URL, "text/html; charset=utf-8", b"<!doctyp"))++ def test_ordinary_page_is_not_a_document(self) -> None:+ self.assertIsNone(+ web_to_md.remote_document_suffix(+ "https://example.org/article", "text/html", b"<html>"))+ self.assertIsNone(+ web_to_md.remote_document_suffix(+ "https://example.org/page.html", "", b"<html>"))+++class PdfBulletTests(unittest.TestCase):+ def test_middot_bullet_is_a_list_item(self) -> None:+ is_list, kind, content = pdf_to_md.detect_list_item("·\x01 Oaks turn red, brown, or russet;")+ self.assertTrue(is_list)+ self.assertEqual(kind, "ul")+ self.assertEqual(content, "- Oaks turn red, brown, or russet;")++ def test_bullet_led_line_is_never_a_heading(self) -> None:+ size_map = {"body": 12.1, "h1": 13.6}+ self.assertEqual(pdf_to_md.get_heading_level(13.6, size_map, "· Oaks turn red", 4), 0)+ self.assertEqual(pdf_to_md.get_heading_level(13.6, size_map, "Autumn colours", 16), 1)++ def test_bullet_glyph_span_detection(self) -> None:+ self.assertTrue(pdf_to_md.is_bullet_glyph_span("· "))+ self.assertTrue(pdf_to_md.is_bullet_glyph_span("•"))+ self.assertTrue(pdf_to_md.is_bullet_glyph_span("·\x01"))+ self.assertFalse(pdf_to_md.is_bullet_glyph_span("Oaks"))+ self.assertFalse(pdf_to_md.is_bullet_glyph_span("· Oaks"))+++class PolygonFilterTests(unittest.TestCase):+ SVG = (+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 720">'+ '<defs><filter id="paperShadow"><feDropShadow dx="0" dy="6" stdDeviation="6" '+ 'flood-color="#000000" flood-opacity="0.25"/></filter></defs>'+ '<polygon id="sheet" points="100,100 400,120 380,400 90,380" fill="#E8D9C4" '+ 'filter="url(#paperShadow)"/>'+ '</svg>'+ )++ def test_polygon_is_a_public_filter_target(self) -> None:+ errors = project_filter_errors(ET.fromstring(self.SVG))+ self.assertEqual([e for e in errors if "cannot use filter" in e], [])++ def test_polygon_exports_its_shadow(self) -> None:+ with tempfile.TemporaryDirectory() as tmp:+ root = Path(tmp)+ svg_path = root / "page.svg"+ svg_path.write_text(self.SVG, encoding="utf-8")+ xml, *_rest = convert_svg_to_slide_shapes(svg_path, resource_root=root)+ self.assertIn("<a:outerShdw", xml)+ self.assertIn("Polygon", xml)+++class SlideSizeTypeTests(unittest.TestCase):+ def test_standard_ratios_keep_their_token(self) -> None:+ self.assertEqual(_slide_size_type(12192000, 6858000), "screen16x9")+ self.assertEqual(_slide_size_type(9144000, 6858000), "screen4x3")+ self.assertEqual(_slide_size_type(10287000, 18288000), "custom")+ self.assertEqual(_slide_size_type(11811000, 16706000), "custom")+++if __name__ == "__main__":+ unittest.main()diff --git a/skills/ppt-master/scripts/text_measure.py b/skills/ppt-master/scripts/text_measure.pyindex 13ed505b..1e9b2acf 100644--- a/skills/ppt-master/scripts/text_measure.py+++ b/skills/ppt-master/scripts/text_measure.py@@ -602,6 +602,12 @@ def _render_calibration_table(payload: dict[str, object], *, include_outline: bo'while authoring (an expanded title, a longer label) is re-estimated ''with the rates — the outline column does not cover it.')+ lines.append(+ '[NOTE] rates ignore letter-spacing and average a mixed-case sample: '+ 'a tracked role (a kicker with letter-spacing) or a display-size line '+ '(a cover title) is sized per string with measure --letter-spacing, '+ 'not from the table.'+ )lines.append('[NOTE] measure and wrap take one --weight for the whole string: a line ''with a bold run (an inline emphasis lead) is measured piecewise per '@@ -658,6 +664,11 @@ def _run_calibrate(args: argparse.Namespace) -> int:weights=weights,)payload['notes'] = _fallback_notes(roles, fallbacks)+ if args.outline and not (project_path / 'design_spec.md').is_file():+ payload['notes'].append(+ 'no design_spec.md in this project (Quick writes none), so the '+ '--outline column has no §IX source and stays empty'+ )bold_roles = sorted(name for name, weight in weights.items() if weight == 'bold')payload['notes'].append('rates for ' + ', '.join(bold_roles) + ' are measured at bold weight'