diff --git a/packages/markitdown/src/markitdown/converters/_pptx_converter.py b/packages/markitdown/src/markitdown/converters/_pptx_converter.py index 360f17706..6eccb819c 100644 --- a/packages/markitdown/src/markitdown/converters/_pptx_converter.py +++ b/packages/markitdown/src/markitdown/converters/_pptx_converter.py @@ -236,7 +236,10 @@ def _convert_chart_to_markdown(self, chart): try: md = "\n\n### Chart" if chart.has_title: - md += f": {chart.chart_title.text_frame.text}" + title_frame = chart.chart_title.text_frame + title_text = title_frame.text if title_frame is not None else "" + if title_text: + md += f": {title_text}" md += "\n\n" data = [] category_names = [c.label for c in chart.plots[0].categories] diff --git a/packages/markitdown/tests/test_module_misc.py b/packages/markitdown/tests/test_module_misc.py index 4d62e4919..103ecae5d 100644 --- a/packages/markitdown/tests/test_module_misc.py +++ b/packages/markitdown/tests/test_module_misc.py @@ -4,9 +4,11 @@ import re import shutil import pytest +from types import SimpleNamespace from unittest.mock import MagicMock from markitdown._uri_utils import parse_data_uri, file_uri_to_path +from markitdown.converters import PptxConverter from markitdown import ( MarkItDown, @@ -532,6 +534,21 @@ def test_markitdown_llm() -> None: validate_strings(result, PPTX_TEST_STRINGS) +def test_pptx_chart_title_without_text_frame_keeps_chart_data() -> None: + chart = MagicMock() + chart.has_title = True + chart.chart_title.text_frame = None + chart.plots = [SimpleNamespace(categories=[SimpleNamespace(label="FY2026")])] + chart.series = [SimpleNamespace(name="Revenue", values=[42])] + + result = PptxConverter()._convert_chart_to_markdown(chart) + + assert "[unsupported chart]" not in result + assert "### Chart\n\n" in result + assert "| Category | Revenue |" in result + assert "| FY2026 | 42 |" in result + + if __name__ == "__main__": """Runs this file's tests from the command line.""" for test in [