Python tool for converting files and office documents to Markdown.
fix(pptx): do not emit a heading for a slide with an empty title (#2442)
kevin075c05bd4d20
diff --git a/packages/markitdown/src/markitdown/converters/_pptx_converter.py b/packages/markitdown/src/markitdown/converters/_pptx_converter.pyindex 5834addb..9b1c6436 100644--- a/packages/markitdown/src/markitdown/converters/_pptx_converter.py+++ b/packages/markitdown/src/markitdown/converters/_pptx_converter.py@@ -180,7 +180,8 @@ class PptxConverter(DocumentConverter):elif shape.has_text_frame:text = shape.text or ""if shape == title:- md_content += "# " + text.lstrip() + "\n"+ if text.strip():+ md_content += "# " + text.lstrip() + "\n"else:md_content += text + "\n"diff --git a/packages/markitdown/tests/test_pptx_empty_title.py b/packages/markitdown/tests/test_pptx_empty_title.pynew file mode 100644index 00000000..b66aaf2c--- /dev/null+++ b/packages/markitdown/tests/test_pptx_empty_title.py@@ -0,0 +1,67 @@+#!/usr/bin/env python3 -m pytest+"""A slide whose title placeholder carries no text must not get a bare heading."""++import io++import pptx++from markitdown import MarkItDown, StreamInfo++BODY_TEXT = "Some body text on the slide."+++def _build_pptx(title: str | None) -> io.BytesIO:+ """Build a one-slide "Title and Content" deck, optionally filling the title.++ Passing None leaves the title placeholder as PowerPoint creates it: present+ on the slide, showing "Click to add title", and carrying no text.+ """+ prs = pptx.Presentation()+ slide = prs.slides.add_slide(prs.slide_layouts[1])+ if title is not None:+ slide.shapes.title.text = title+ slide.placeholders[1].text = BODY_TEXT+ buf = io.BytesIO()+ prs.save(buf)+ buf.seek(0)+ return buf+++def _convert(title: str | None) -> str:+ return (+ MarkItDown()+ .convert_stream(_build_pptx(title), stream_info=StreamInfo(extension=".pptx"))+ .markdown+ )+++def _heading_lines(markdown: str) -> list[str]:+ return [line for line in markdown.splitlines() if line.startswith("#")]+++def test_untouched_title_placeholder_produces_no_heading() -> None:+ markdown = _convert(None)++ assert BODY_TEXT in markdown+ assert _heading_lines(markdown) == []+++def test_empty_title_produces_no_heading() -> None:+ markdown = _convert("")++ assert BODY_TEXT in markdown+ assert _heading_lines(markdown) == []+++def test_whitespace_only_title_produces_no_heading() -> None:+ markdown = _convert(" ")++ assert BODY_TEXT in markdown+ assert _heading_lines(markdown) == []+++def test_title_with_text_is_still_emitted() -> None:+ markdown = _convert("Quarterly Results")++ assert "# Quarterly Results" in markdown+ assert BODY_TEXT in markdown