fix(pptx): convert soft line breaks instead of emitting a vertical tab - #2513
Open
Lukas (L4XB) wants to merge 1 commit into
Open
Lukas (L4XB) wants to merge 1 commit into
Lukas (L4XB) wants to merge 1 commit into
Conversation
Shift+Enter inside a PowerPoint paragraph is an `<a:br/>`, and python-pptx reports it as `\v`. The converter passes `shape.text`, `cell.text`, the notes text and the chart title straight through, so that vertical tab reaches the Markdown. It is a C0 control, not Markdown: renderers drop it, so the two lines run together, and nothing downstream treats it as whitespace either. Normalize it where the text enters. A shape's own paragraphs already arrive joined with newlines, so a soft break reads the same way. A table cell keeps its row: the newline goes into the HTML the table is built from, where it is ordinary whitespace and collapses to a space. A slide title is a special case: an ATX heading cannot span lines, so a newline there would close the heading and leave the rest as body text. Titles now collapse their line breaks to spaces, which also fixes the multi-paragraph titles that already produced a stray body line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Shift+Enter inside a PowerPoint paragraph is an
<a:br/>— one paragraph, twolines — and python-pptx reports it as
\v.PptxConverterpassesshape.text,cell.text, the notes text and the chart title straight through, so thatvertical tab lands in the Markdown:
A vertical tab is a C0 control, not Markdown. A renderer drops it, so the two
lines run together (
ADDRESS LINE ONEADDRESS LINE TWO), and nothing downstreamtreats it as whitespace either — a splitter sees one long line and a tokenizer
sees one strange token. Address blocks, signature blocks and "name / title"
boxes are where this shows up, which is most of the text in a deck's smaller
shapes.
After:
What changed
One helper, applied where the text enters:
\vbecomes\n. A shape's ownparagraphs already arrive joined with
\n, so a soft break now reads the sameway, and the table path needs nothing special — the newline goes into the HTML
the table is built from, where it is ordinary whitespace and collapses to a
space, so the row stays one row.
A slide title is the one place a newline cannot go: an ATX heading ends at the
line break, which would leave the rest of the title as body text. Titles
therefore collapse their line breaks to spaces. That also repairs the
already-broken case of a multi-paragraph title, which produces
# First\nSecondtoday.Tests
test_pptx_soft_line_breaks_are_not_vertical_tabsinpackages/markitdown/tests/test_module_misc.pybuilds a deck with a soft breakin a title, a text box, a header cell, a body cell and the speaker notes, then
asserts no
\vsurvives and each one reads correctly.The 893 include the reference
test.pptxvector, so the title change is coveredagainst a real deck as well as the synthetic one.
black==23.7.0(the pinned pre-commit version) leaves both files unchanged.