Repository navigation
fix(pptx): preserve run-level hyperlinks and character formatting - #4443
avanish-garg wants to merge 7 commits into
Conversation
|
✅ DCO Check Passed Thanks @avanish-garg, all your commits are properly signed off. 🎉 |
Merge Protections🔴 1 of 2 protections blocking · waiting on 👀 reviews
🔴 Require two reviewer for test updatesWaiting for
This rule is failing.When test data is updated, we require two reviewers
Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
d13aba6 to
7e92359
Compare
ceberam
left a comment
There was a problem hiding this comment.
Thanks @avanish-garg for this PR, since indeed the PPTX backend was not yet keeping the formatting unlike the other Office backends.
The new code and tests are technically sound and functionally correct.
My only recommendation would be to clean up the excessive inline commentary and verbose private docstrings.
There are multiple lengthy inline comment blocks that explain why previous behavior was buggy, detail developer rationale, or repeat method-level documentation. The inline comments in Docling should also limit explanations on how third-party applications like PowerPoint work, since developers and maintainers can refer to the documentation of those applications directly, if necessary.
|
Thanks for the review @ceberam. Done with the changes! |
ceberam
left a comment
There was a problem hiding this comment.
Thanks @avanish-garg for addressing my comment.
All good from my side.
|
@avanish-garg do you mind having a last round fixing the conflict with |
0c25dba to
0d3aed1
Compare
AI triage (advisory)Checked commit The PPTX backend now reads each paragraph run by run. It keeps run-level hyperlinks and bold, italic and underline formatting, and it exports multi-run blocks as inline groups. Body text items now use the CI safety: no concern found. A maintainer must still approve CI. 2 related pull request(s) in the same code
Reference data changes
Assessment: expected. The PR intentionally changes body text from the The |
0d3aed1 to
2513684
Compare
ceberam
left a comment
There was a problem hiding this comment.
@avanish-garg I've just seen a blocking issue and added a couple of suggestions worth addressing.
|
Hi @avanish-garg, thank you for this pull request. It has a merge conflict with git fetch upstream
git rebase upstream/main
# resolve the conflicts, then:
git push --force-with-leaseWe can continue with the review and CI after that. |
|
@avanish-garg a heads-up for your rebase: since #3891 and docling-core 2.106.0, serializers join The goldens also need regenerating. For example, |
450cdac to
71f365f
Compare
71f365f to
55c336c
Compare
The PPTX text-extraction loop built each paragraph's text via plain
string concatenation (p_text += e.text) and handed the whole thing to
a single add_text/add_list_item call, discarding every run's own
hyperlink and bold/italic/underline formatting - the same information
DOCX/HTML/ODF/MD backends already preserve per run.
Splits each paragraph into (text, formatting, hyperlink) tuples per
run, mirroring msword_backend.py's existing _iter_paragraph_content/
_get_format_from_run/_get_hyperlink_target pattern:
- Adjacent runs with identical formatting/hyperlink are coalesced back
into one unit first, since PowerPoint sometimes splits a single word
across runs with no actual formatting difference (e.g. spell-check
markup) - without this, wrapping each such run in its own item would
let the markdown serializer's inter-sibling space split real words.
- A paragraph with more than one run is wrapped in an inline group
(mirroring the DOCX backend's own _create_or_reuse_parent), so a
sentence with a bold word or a link in the middle stays one flowing
unit on export instead of splintering into separate blocks.
- Title/section-header paragraphs are kept as a single item as before:
a heading is one outline-level unit, not a sequence of independently
formatted spans.
- Each item's own provenance is now built from its own text rather
than the whole paragraph's, so charspan stays correct once a
paragraph can produce more than one item (python-pptx exposes no
finer bbox than the shape's, so the bbox itself stays shape-level).
New test: test_pptx_preserves_run_level_formatting_and_hyperlinks,
covering a bold run, a plain run, and a hyperlinked run in one
paragraph. Golden fixtures regenerated; diffs are exactly the fixed
behavior (a real markdown hyperlink where the URL was silently
dropped, formatting: {...} now present throughout) with no unrelated
changes.
Native Office Math equations (docling-project#4625) keep their own FORMULA items; the text
runs around them now carry their run-level formatting and hyperlinks too.
Signed-off-by: Avanish Garg <gargavanish@gmail.com>
55c336c to
2955915
Compare
|
@ceberam I rebased this PR onto the current main again, because it had conflicts after the recent table, chart and archive-limit changes in the PowerPoint backend. The only conflict was a placement one, where a new module constant sits next to the run helper; the PR content is unchanged, and no ground-truth files changed. All PowerPoint tests pass locally (157 passed). The force-push dismissed your earlier approval. Could you approve it again when you have a moment? Thanks. |
`run.hyperlink.address` returns the relationship target of the click action. For an internal action, such as a jump to another slide, that target is a part name (`slide2.xml`), so a text run could export a local path that no reader can follow. Keep a run link only for the `HYPERLINK` and `OPEN_FILE` actions, the rule `_shape_hyperlink` already applies, and share the address-to-target conversion in `_hyperlink_target`. The new test puts a slide-jump run next to a URL run. Reference data does not change. Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
A title stays one item, so a title whose whole heading pointed at one target lost that target. The item now carries the target that all its text runs share. A title whose runs point at different targets keeps its text and no target, because one field cannot describe several links. A link on the paragraph-end mark (`a:endParaRPr/a:hlinkClick`) stays dropped on purpose: the mark has no text, so no item can carry its target. The reason is now in the docstring, and a test checks that the text survives without the link. Reference data does not change. Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
ceberam
left a comment
There was a problem hiding this comment.
Hi Avanish,
Thanks for this PR and for keeping it alive with your latest rebase.
While reviewing it again, I found one incorrect output and a few gaps, so I added six commits on top of yours; your commit 2955915 is unchanged and remains the first one. Here is what they do and why:
- Run links that are not links. A run whose click action is a jump to another slide was exported as a link to
slide2.xml, becausepython-pptxresolves an internal relationship to a part name. A run link now keeps only the HYPERLINK and OPEN_FILE actions, the samerule _shape_hyperlinkfollows since #4787, with a regression test. - Titles. A title keeps its single-item contract and now also keeps the link that all its runs share. A title whose runs point at different targets keeps the text and no target, because one field cannot describe several links. Run formatting still does not apply to a title.
- Labels. Body text items now use the text label instead of paragraph, since this is the standard the backends should follow for regular text. The ground truth files changed only in that field.
- Paragraph-end mark. The
a:endParaRPr/a:hlinkClicklink from the report in #4442 stays dropped, now on purpose, with a note in the code and a test: the mark has no text, so no item can carry the target. - Smaller cleanups. Google-style docstrings for the run and list-item helpers, one annotation style for the hyperlink targets, and malformed or dangling links handled as the DOCX backend does.
- Tests. The run-link tests share helpers and use parametrization, the call-count test is gone, and there is a new round-trip fixture,
tests/data/pptx/sources/powerpoint_run_hyperlink.pptx, with one slide per case and reference data in Markdown, indented text and JSON. The source discovery skips the ~$ lock files that PowerPoint creates while a deck is open.
I also updated the PR description to describe the final behavior, the review decisions and the known limitations. Your commit is untouched.
Feel free to add any comment, but from my perspective the PR is ready to be merged.
Thanks again for the work 🚀
d8ef998 to
5b67b74
Compare
Use `TEXT` instead of `PARAGRAPH` label in body text items. The ground truth files only change the label. Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
Share the deck, run and XML helpers between the tests, assert the expected (text, bold, link) rows, and cover the title rule as two cases. Drop the test that counted calls to the private run helper. Reference data does not change. Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
One slide per case: a linked title, a title whose runs link to different targets, whitespace-only runs and a soft line break, bullets with an absolute and a relative link, a slide jump and a paragraph-mark link (both dropped), runs around an equation, and a shape link next to a run with its own link. Source discovery skips the `~$` lock files that PowerPoint creates while a deck is open. Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
5b67b74 to
cb0e19e
Compare
MsPowerpointDocumentBackendbuilt each paragraph's text with plain string concatenation and passed the whole paragraph to a singleadd_textoradd_list_itemcall, so every run-level hyperlink and every bold, italic or underlined run was discarded. This PR reads a paragraph run by run, keeps the formatting and the link of each run, and exports the runs of a block as an inline group, as the DOCX, HTML, ODF and Markdown backends already do.Changes
(label, text, formatting, hyperlink)unit. Adjacent runs with the same formatting and link are coalesced, because PowerPoint often splits a word across runs. Whitespace inside a block is kept, and only its outer edges are trimmed.HYPERLINKandOPEN_FILEclick actions, the rule that the whole-shape link from fix(pptx): keep a hyperlink attached to a whole shape #4787 follows. A slide jump resolves to a part name (slide2.xml) and is dropped. A dangling, empty or missing relationship drops the target and keeps the text.textlabel, like the DOCX backend, instead ofparagraph.a:endParaRPr/a:hlinkClickis dropped on purpose, because the mark has no text that could carry it.tests/test_backend_pptx_runs.pycovers the cases above with shared helpers and parametrization, and the new fixturetests/data/pptx/sources/powerpoint_run_hyperlink.pptxjoins the round-trip test. Source discovery now skips the~$lock files that PowerPoint creates while a deck is open.No documentation or example change is needed: the PPTX output now matches the DOCX backend, and the new fixture is the example.
Issue resolved by this Pull Request:
Resolves #4442
Checklist:
Review evidence:
Before: the paragraph
Bold+plain+ a linkedlinkproduced one item,Bold plain link, with noformattingand nohyperlink. A title with a linked run lost the link. A run that jumps to another slide produced[See slide 2](slide2.xml). Every body item carried theparagraphlabel.After: the same paragraph gives three items inside an inline group, with
bold=Trueon the first andhttps://example.com/docson the last. The title keeps the link that its runs share. The slide jump keeps its text and no link. Body items carry thetextlabel.Source, document tree and exports: the new fixture has one slide per case, and its Markdown, indented-text and JSON reference files are generated from it. The Markdown shows
**Bold** plain [link](https://example.com/docs),# [Run-level links](https://example.com/docling),- Fixed [appendix](appendix/notes.docx)and**Energy is** $E=mc^2$ [in this model.](https://example.com/energy). The indented text shows the inline groups and the equation as aformulaitem in place. The JSON holds 24formattingobjects and 8hyperlinkfields.Reference-data changes: the six existing PPTX JSON and
.itxtfixtures change only where a label changes fromparagraphtotext(21 items, with no change to text, order, geometry or provenance).Commands and results:
pytest tests/test_backend_pptx.py tests/test_backend_pptx_runs.py: 55 passed.pyteston the 11 PPTX test modules: 155 passed.make check(ruff, ty, tach, max-lines, dprint,uv lock --locked): exit 0.mc:AlternateContent.