fix(pptx): read a line break as a newline instead of a vertical tab
Merged
L4
13d ago+44+44+01234567890123456789-5-5-0123456789
Summary
python-pptx returns a line break inside a paragraph (Shift+Enter in PowerPoint, <a:br/> in the XML) as a vertical tab (\v). partition_pptx() passes paragraph.text through unchanged, so that control character ends up in the element text of titles, text boxes and slide notes:
| source | element text on main | with this PR |
|---|---|---|
title Quarterly ⏎ results | 'Quarterly\x0bresults' | 'Quarterly\nresults' |
text box First line ⏎ second line | 'First line\x0bsecond line' | 'First line\nsecond line' |
slide notes Note one ⏎ note two | 'Note one\x0bnote two' | 'Note one\nnote two' |
Table cells were already unaffected, because their text goes through the HTML table normalization.
Change
A small _break_lines() helper replaces \v with \n. It is used for paragraph text in _iter_shape_elements() and _iter_title_shape_element(), and for the slide-notes text. A newline is how the DOCX partitioner already gives a w:br line break, since python-docx reads it as \n.
Testing
- New
test_partition_pptx_reads_line_breaks_as_newlinesbuilds a slide with a line break in the title, in a text box and in the notes. It fails onmain. - The other 73 tests in
test_pptx.pypass. The.ppttests need LibreOffice, which isn't installed here. - ruff 0.15.10 check and format are clean, and
scripts/version-sync.sh -cpasses with0.27.34-dev1.