Skip to content

fix(pptx): emit a blank line between PowerPoint paragraphs - #2759

Open
PerryLink (PerryLink) wants to merge 1 commit into
microsoft:mainfrom
PerryLink:pptx-paragraph-blocks
Open

PerryLink (PerryLink) wants to merge 1 commit into
microsoft:mainfrom
PerryLink:pptx-paragraph-blocks

Conversation

@PerryLink

Copy link
Copy Markdown

PptxConverter writes a body text frame with shape.text, which python-pptx joins with a single \n between paragraphs. A single newline is a CommonMark soft break, so separate paragraphs render as one continuous line:

prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "Quarterly review"
frame = slide.placeholders[1].text_frame
frame.text = "Revenue grew 12% year over year."
frame.add_paragraph().text = "Costs stayed flat."
frame.add_paragraph().text = "Outlook is positive."

Actual:

# Quarterly review
Revenue grew 12% year over year.
Costs stayed flat.
Outlook is positive.

which renders as one paragraph — "…year over year. Costs stayed flat. Outlook is positive."

Expected (separate paragraphs, like the DOCX and HTML converters produce):

# Quarterly review
Revenue grew 12% year over year.

Costs stayed flat.

Outlook is positive.

The trailing-double-space alternative (requested in #1331) cannot work here: _markitdown.py rstrips every output line before joining, so the spaces are gone by the time the Markdown is returned. A blank line is preserved (the normalizer only collapses runs of three or more newlines).

Change

Join the paragraphs of a body text frame with a blank line instead of writing shape.text as-is. Title handling is unchanged.

Test

packages/markitdown/tests/test_pptx.py::test_body_paragraphs_are_separate_markdown_paragraphs builds the deck above, asserts the blank-line separation, and asserts that . Costs stayed flat. does not appear. It fails on main and passes with the change; test_pptx.py is 50 passed.

Related: #1331 (hard breaks in PPTX), #1911 and #2513 (hyperlinks/lists and soft line breaks inside a paragraph) are complementary and still join paragraphs with a single newline.

python-pptx joins the paragraphs of a text frame with a single newline, and
the converter wrote that string as-is. A single newline is a CommonMark soft
break, so separate bullet-less paragraphs rendered as one continuous line.
Join the paragraphs with a blank line instead, matching how the DOCX and HTML
converters emit separate blocks. Trailing spaces would not survive the
normalizer, which rstrips every output line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant