diff --git a/packages/markitdown-ocr/src/markitdown_ocr/_pptx_converter_with_ocr.py b/packages/markitdown-ocr/src/markitdown_ocr/_pptx_converter_with_ocr.py index 7e91ed6b4..455311fe1 100644 --- a/packages/markitdown-ocr/src/markitdown_ocr/_pptx_converter_with_ocr.py +++ b/packages/markitdown-ocr/src/markitdown_ocr/_pptx_converter_with_ocr.py @@ -222,7 +222,7 @@ def _convert_table_to_markdown(self, table, **kwargs): def _convert_chart_to_markdown(self, chart): try: md = "\\n\\n### Chart" - if chart.has_title: + if chart.has_title and chart.chart_title.text_frame is not None: md += f": {chart.chart_title.text_frame.text}" md += "\\n\\n" data = [] diff --git a/packages/markitdown-ocr/tests/test_pptx_converter.py b/packages/markitdown-ocr/tests/test_pptx_converter.py index 724f1039c..bdcc4ee10 100644 --- a/packages/markitdown-ocr/tests/test_pptx_converter.py +++ b/packages/markitdown-ocr/tests/test_pptx_converter.py @@ -146,3 +146,29 @@ def test_pptx_no_ocr_service_no_tags() -> None: md = converter.convert(f, StreamInfo(extension=".pptx")).text_content assert "*[Image OCR]" not in md assert "[End OCR]*" not in md + + +def test_pptx_ocr_chart_no_title_text_frame() -> None: + from unittest.mock import MagicMock + from markitdown_ocr._pptx_converter_with_ocr import PptxConverterWithOCR + + mock_chart = MagicMock() + mock_chart.has_title = True + mock_chart.chart_title.text_frame = None + + mock_category = MagicMock() + mock_category.label = "Cat 1" + mock_chart.plots = [MagicMock(categories=[mock_category])] + + mock_series = MagicMock() + mock_series.name = "Series 1" + mock_series.values = [10.0] + mock_chart.series = [mock_series] + + converter = PptxConverterWithOCR() + result = converter._convert_chart_to_markdown(mock_chart) + + assert "### Chart" in result + assert "Cat 1" in result + assert "Series 1" in result + assert ":" not in result diff --git a/packages/markitdown/src/markitdown/converters/_pptx_converter.py b/packages/markitdown/src/markitdown/converters/_pptx_converter.py index 360f17706..96b89a120 100644 --- a/packages/markitdown/src/markitdown/converters/_pptx_converter.py +++ b/packages/markitdown/src/markitdown/converters/_pptx_converter.py @@ -235,7 +235,7 @@ def _convert_table_to_markdown(self, table, **kwargs): def _convert_chart_to_markdown(self, chart): try: md = "\n\n### Chart" - if chart.has_title: + if chart.has_title and chart.chart_title.text_frame is not None: md += f": {chart.chart_title.text_frame.text}" md += "\n\n" data = [] diff --git a/packages/markitdown/tests/test_module_misc.py b/packages/markitdown/tests/test_module_misc.py index 4d62e4919..1183fc292 100644 --- a/packages/markitdown/tests/test_module_misc.py +++ b/packages/markitdown/tests/test_module_misc.py @@ -532,6 +532,31 @@ def test_markitdown_llm() -> None: validate_strings(result, PPTX_TEST_STRINGS) +def test_pptx_chart_no_title_text_frame() -> None: + from markitdown.converters._pptx_converter import PptxConverter + + mock_chart = MagicMock() + mock_chart.has_title = True + mock_chart.chart_title.text_frame = None + + mock_category = MagicMock() + mock_category.label = "Cat 1" + mock_chart.plots = [MagicMock(categories=[mock_category])] + + mock_series = MagicMock() + mock_series.name = "Series 1" + mock_series.values = [10.0] + mock_chart.series = [mock_series] + + converter = PptxConverter() + result = converter._convert_chart_to_markdown(mock_chart) + + assert "### Chart" in result + assert "Cat 1" in result + assert "Series 1" in result + assert ":" not in result + + if __name__ == "__main__": """Runs this file's tests from the command line.""" for test in [ @@ -547,6 +572,7 @@ def test_markitdown_llm() -> None: test_markitdown_exiftool, test_markitdown_llm_parameters, test_markitdown_llm, + test_pptx_chart_no_title_text_frame, ]: print(f"Running {test.__name__}...", end="") test()