Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
26 changes: 26 additions & 0 deletions packages/markitdown-ocr/tests/test_pptx_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
26 changes: 26 additions & 0 deletions packages/markitdown/tests/test_module_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand All @@ -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()
Expand Down