Repository navigation
fix(pptx): keep soft line breaks with markdown and plain link formats - #13222
Open
Rainmemery wants to merge 2 commits into
Open
Rainmemery wants to merge 2 commits into
Rainmemery wants to merge 2 commits into
Conversation
`_process_paragraph` built its output from `paragraph.runs`, which yields only the `<a:r>` children. A soft line break (`<a:br/>`, Shift+Enter) standing between two runs was therefore dropped, so with link_format="markdown" or "plain" the two sides were glued together: a text box holding "Account: Alice", a break, and "Balance: 100" became the single token "Account: AliceBalance: 100", which retrieval cannot match. The default "none" mode, which returns `paragraph.text`, already kept the break. Walk the paragraph children instead and emit each break as the vertical tab that python-pptx itself uses in `paragraph.text`, so every link format returns the same text, and hyperlinked runs keep their formatting. Fixes deepset-ai#13043
Contributor
|
@Rainmemery is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
The three new tests annotated the parametrized link_format as str, which mypy rejects: PPTXToDocument's constructor takes Literal['markdown', 'plain', 'none']. The pre-existing parametrized test leaves the parameter unannotated (implicitly Any); annotating it as Literal['markdown', 'plain'] keeps the defs complete and mypy clean. Fixes the mypy CI failure on deepset-ai#13222.
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
This branch has not been deployed
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.
Related Issues
Proposed Changes:
With
link_format="markdown"or"plain",_process_paragraphbuilt its output fromparagraph.runs, which yields only the<a:r>children. A soft line break (<a:br/>,Shift+Enter) standing between two runs was therefore dropped and the two sides were glued
together: a text box holding
Account: Alice, a soft line break, andBalance: 100wasconverted into the single token
Account: AliceBalance: 100, which retrieval cannot match.The default
link_format="none", which returnsparagraph.text, already kept the break.The link-formatting branch now walks the paragraph's children in document order instead of
just its runs, and emits each
<a:br/>as the vertical tab python-pptx itself uses inparagraph.text. All three link formats therefore return the same text, and hyperlinkedruns keep their existing formatting.
How did you test it?
Unit tests: three regressions in
test/components/converters/test_pptx_to_document.py—test_soft_line_break_with_link_format— the report's exact repro, for both formats;test_soft_line_break_matches_link_format_none— the formatted output equals whatlink_format="none"already returns;test_hyperlink_still_formatted_next_to_soft_line_break— a break next to a hyperlinkedrun still yields
[example](https://example.com)/example (https://example.com).Red/green: the new tests fail on unpatched
main(6 cases; the vertical tab is missing) andpass with the change. The whole PPTX module is green (17 passed). A before/after run of
test/components/convertersgoes from 133 failed / 189 passed to 127 failed / 195 passed —the difference is exactly these 6 cases, so nothing else moved; the remaining failures are
optional dependencies missing in my environment (pypdf, pdfminer, beautifulsoup) and are
identical before and after.
ruff checkandruff format --checkare clean on both files.I could not run
hatch run test:types: my sandbox cannot reach PyPI to install mypy. The newcode narrows
paragraph._p.iterchildren()withisinstanceagainst the annotatedpptx.oxml.textclasses rather than casting, so it should type-check cleanly.Notes for the reviewer
on review grounds, and nothing has referenced the issue since.
<a:r>and<a:br/>children are handled, matching the previous behaviour for everyother paragraph child (fields were already dropped in the formatted modes).
understood by me before submitting.
Checklist
fix:.ruff check,ruff format) and fixed any issue.