Skip to content

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(source-to-md): keep PowerPoint chart titles and picture alt text

hugohe36d1cb8ff891a
diff --git a/skills/ppt-master/scripts/docs/conversion.md b/skills/ppt-master/scripts/docs/conversion.md
index 733e0af0..ace22998 100644
--- a/skills/ppt-master/scripts/docs/conversion.md
+++ b/skills/ppt-master/scripts/docs/conversion.md
@@ -234,6 +234,7 @@ python3 scripts/source_to_md/ppt_to_md.py template.ppsx -o notes/template.md
Behavior:
- extracts slide text in reading order
- rewrites Office Math equations (`a14:m` OMML) as `$...$` inline or `$$...$$` display LaTeX, using the same converter as `.docx`
+- uses a chart's own visible title in its `> [Chart]` header, and a picture's alt text (`descr`) as its Markdown alt text
- reads the `mc:Fallback` of other shape-tree `mc:AlternateContent` it cannot interpret (3D models, ink, zoom), so their preview pictures and text are kept; ChartEx stays reported as unsupported
- converts PowerPoint tables to Markdown tables; cell-internal line breaks become `<br>` so they cannot break the pipe-table row structure
- transcribes category charts as category × series tables and scatter/bubble charts as typed X/Y[/size] point tables
diff --git a/skills/ppt-master/scripts/source_to_md/ppt_to_md.py b/skills/ppt-master/scripts/source_to_md/ppt_to_md.py
index 62d43e97..a5cedf9d 100644
--- a/skills/ppt-master/scripts/source_to_md/ppt_to_md.py
+++ b/skills/ppt-master/scripts/source_to_md/ppt_to_md.py
@@ -670,6 +670,24 @@ def _format_chart_value(value: object) -> str:
return str(value)
+def _chart_title_text(chart: object) -> str:
+ """Return the chart's own visible title text, if it has one."""
+ try:
+ if chart.has_title and chart.chart_title.has_text_frame:
+ return chart.chart_title.text_frame.text
+ except (ValueError, AttributeError, KeyError):
+ pass
+ return ""
+
+
+def _picture_alt_text(shape: object) -> str:
+ """Return the author's alt text (cNvPr/@descr) as a Markdown-safe label."""
+ element = getattr(shape, "_element", None)
+ names = element.xpath("./*/p:cNvPr") if element is not None else []
+ description = normalize_text(names[0].get("descr") or "") if names else ""
+ return _escape_md_link_text(description.replace("\n", " "))
+
+
def _chart_header(chart: object, name: str) -> tuple[str, str]:
"""Return the Markdown chart header and its best-effort type label."""
try:
@@ -677,7 +695,10 @@ def _chart_header(chart: object, name: str) -> tuple[str, str]:
except (ValueError, AttributeError, KeyError):
chart_type = ""
raw_name = "" if name is None else str(name)
- chart_name = normalize_text(raw_name).replace("\n", " ") or "Chart"
+ chart_name = (
+ normalize_text(_chart_title_text(chart) or raw_name).replace("\n", " ")
+ or "Chart"
+ )
header = f"> [Chart] {chart_name}" + (f" — {chart_type}" if chart_type else "")
return header, chart_type
@@ -1404,16 +1425,21 @@ def convert_presentation_to_markdown(
)
if saved_picture is None:
if is_picture_shape:
- blocks.append(f"> [Image] {getattr(shape, 'name', 'Picture')}")
+ blocks.append(
+ f"> [Image] {_picture_alt_text(shape) or getattr(shape, 'name', 'Picture')}"
+ )
continue
else:
if saved_picture.is_new_asset:
image_count = next_image_index
image_manifest.append(saved_picture.manifest_entry)
asset_dir_used = True
+ alt_text = (
+ _picture_alt_text(shape)
+ or f"Slide {slide_index} Image {image_ref_count}"
+ )
image_markdown = (
- f"![Slide {slide_index} Image {image_ref_count}]"
- f"({asset_dir.name}/{saved_picture.filename})"
+ f"![{alt_text}]({asset_dir.name}/{saved_picture.filename})"
)
image_link = _shape_click_target(shape)
if image_link is not None:
diff --git a/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_pptx.py b/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_pptx.py
index fca83c06..6c2f5b7f 100644
--- a/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_pptx.py
+++ b/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_pptx.py
@@ -238,6 +238,34 @@ class PptxContentLossTests(unittest.TestCase):
self.assertIn('caption', md)
self.assertRegex(md, r'!\[[^\]]*\]\([^)]+\.png\)')
+ def test_chart_header_uses_the_visible_chart_title(self) -> None:
+ from pptx.chart.data import CategoryChartData
+ from pptx.enum.chart import XL_CHART_TYPE
+
+ prs, _ = self._presentation()
+ data = CategoryChartData()
+ data.categories = ['North']
+ data.add_series('Sales', (3,))
+ chart = prs.slides[0].shapes.add_chart(
+ XL_CHART_TYPE.COLUMN_CLUSTERED, Inches(1), Inches(3), Inches(4), Inches(3), data,
+ ).chart
+ chart.has_title = True
+ chart.chart_title.text_frame.text = 'Revenue by region'
+ md = self._convert(prs)
+ self.assertIn('> [Chart] Revenue by region', md)
+
+ def test_picture_alt_text_becomes_markdown_alt(self) -> None:
+ from PIL import Image
+
+ prs, _ = self._presentation()
+ with tempfile.TemporaryDirectory() as tmp:
+ image = Path(tmp) / 'map.png'
+ Image.new('RGB', (40, 40), 'blue').save(image)
+ picture = prs.slides[0].shapes.add_picture(str(image), Inches(1), Inches(3))
+ picture._element.nvPicPr.cNvPr.set('descr', 'Map of [north] sites')
+ md = self._convert(prs)
+ self.assertIn(r'![Map of \[north\] sites](', md)
+
def test_chartex_fallback_text_is_not_read_as_slide_text(self) -> None:
prs, shape = self._presentation()
shape.text = "This chart isn't available in your version of PowerPoint"