Skip to content

fix(pptx): preserve run-level hyperlinks and character formatting - #4443

Open
avanish-garg wants to merge 7 commits into
docling-project:mainfrom
avanish-garg:fix/pptx-drops-hyperlinks-and-formatting
Open

avanish-garg wants to merge 7 commits into
docling-project:mainfrom
avanish-garg:fix/pptx-drops-hyperlinks-and-formatting

Conversation

@avanish-garg

@avanish-garg avanish-garg commented Sep 29, 2026 •

Copy link
Copy Markdown

MsPowerpointDocumentBackend built each paragraph's text with plain string concatenation and passed the whole paragraph to a single add_text or add_list_item call, 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

  • Runs: each run becomes a (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.
  • Structure: a paragraph with several runs or an equation becomes an inline group, and a paragraph with one run stays a single item. Each item carries the character span of its own text and the bounding box of its shape.
  • Links: a run link is kept only for the HYPERLINK and OPEN_FILE click 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.
  • Titles: a title stays one outline-level item and keeps the link that all of its text runs share. A title whose runs point at different targets keeps its text and no target.
  • Labels: body text items use the text label, like the DOCX backend, instead of paragraph.
  • Paragraph-end mark: a link stored in a:endParaRPr/a:hlinkClick is dropped on purpose, because the mark has no text that could carry it.
  • Tests: tests/test_backend_pptx_runs.py covers the cases above with shared helpers and parametrization, and the new fixture tests/data/pptx/sources/powerpoint_run_hyperlink.pptx joins the round-trip test. Source discovery now skips the ~$ lock files that PowerPoint creates while a deck is open.
  • The run and list-item helpers have Google-style docstrings.

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:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Review evidence:

Before: the paragraph Bold + plain + a linked link produced one item, Bold plain link, with no formatting and no hyperlink. 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 the paragraph label.

After: the same paragraph gives three items inside an inline group, with bold=True on the first and https://example.com/docs on the last. The title keeps the link that its runs share. The slide jump keeps its text and no link. Body items carry the text label.

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 a formula item in place. The JSON holds 24 formatting objects and 8 hyperlink fields.

Reference-data changes: the six existing PPTX JSON and .itxt fixtures change only where a label changes from paragraph to text (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.
  • pytest on the 11 PPTX test modules: 155 passed.
  • make check (ruff, ty, tach, max-lines, dprint, uv lock --locked): exit 0.
  • The new deck renders in LibreOffice as six pages, which confirms the layout and that the equation paragraph survives a renderer that honours mc:AlternateContent.

@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @avanish-garg, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit —

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.10390% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/mspowerpoint_backend.py 96.10% 1 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@avanish-garg
avanish-garg force-pushed the fix/pptx-drops-hyperlinks-and-formatting branch from d13aba6 to 7e92359 Compare October 7, 2026 13:25
@ceberam ceberam added bug Something isn't working pptx issue related to pptx backend labels Oct 7, 2026

@ceberam ceberam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@avanish-garg

Copy link
Copy Markdown
Author

Thanks for the review @ceberam. Done with the changes!

ceberam
ceberam previously approved these changes Oct 7, 2026

@ceberam ceberam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @avanish-garg for addressing my comment.
All good from my side.

dolfim-ibm
dolfim-ibm previously approved these changes Oct 8, 2026
@dolfim-ibm

Copy link
Copy Markdown
Member

@avanish-garg do you mind having a last round fixing the conflict with main?

@avanish-garg
avanish-garg dismissed stale reviews from dolfim-ibm and ceberam via 0d3aed1 October 8, 2026 13:58
@avanish-garg
avanish-garg force-pushed the fix/pptx-drops-hyperlinks-and-formatting branch from 0c25dba to 0d3aed1 Compare October 8, 2026 13:58
@github-actions github-actions Bot added the ai:ci-safe AI triage found no CI-safety concern (advisory) label Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit cb0e19ed02. The analysis read the diff only. It did not run code from this pull request.

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 text label instead of paragraph.

CI safety: no concern found. A maintainer must still approve CI.

2 related pull request(s) in the same code
PR State Signal Assessment
#4787 merged referenced as #4787; also references issue #4442 related: The merged PR keeps a hyperlink that is attached to a whole shape. This PR keeps run-level links and formatting. It reuses the shape-link helper through the new _hyperlink_target, and it does not repeat that change.
#5172 closed also references issue #4442 related: The candidate tries to fix the same run-level link and formatting problem in the same file. It is closed and not merged, so it does not block this PR.

Reference data changes

Change Files
structure 7
text 9
added 3
  • structure tests/data/ppt/groundtruth/legacy_sample.ppt.json: paragraph: 5 → 0; text: 2 → 7
  • structure tests/data/pptx/groundtruth/powerpoint_comments.pptx.json: paragraph: 2 → 0; text: 4 → 8
  • structure tests/data/pptx/groundtruth/powerpoint_issue_2663.pptx.json: paragraph: 2 → 0; text: 0 → 2
  • structure tests/data/pptx/groundtruth/powerpoint_malformed_pictures.pptx.json: paragraph: 3 → 0; text: 0 → 3
  • structure tests/data/pptx/groundtruth/powerpoint_sample.pptx.json: paragraph: 5 → 0; text: 2 → 7
  • structure tests/data/pptx/groundtruth/powerpoint_unrecognized_shape.pptx.json: paragraph: 4 → 0; text: 0 → 4
  • structure tests/data/pptx/groundtruth/powerpoint_with_image.pptx.json: paragraph: 3 → 0; text: 0 → 3
  • text tests/data/ppt/groundtruth/legacy_sample.ppt.itxt: +5 / -5 lines
  • text tests/data/pptx/groundtruth/powerpoint_comments.pptx.itxt: +11 / -8 lines
  • text tests/data/pptx/groundtruth/powerpoint_comments.pptx.md: +1 / -1 lines
  • text tests/data/pptx/groundtruth/powerpoint_issue_2663.pptx.itxt: +2 / -2 lines
  • text tests/data/pptx/groundtruth/powerpoint_issue_2663.pptx.md: +2 / -2 lines
  • text tests/data/pptx/groundtruth/powerpoint_malformed_pictures.pptx.itxt: +3 / -3 lines
  • text tests/data/pptx/groundtruth/powerpoint_sample.pptx.itxt: +5 / -5 lines
  • text tests/data/pptx/groundtruth/powerpoint_unrecognized_shape.pptx.itxt: +4 / -4 lines
  • text tests/data/pptx/groundtruth/powerpoint_with_image.pptx.itxt: +3 / -3 lines
  • added tests/data/pptx/groundtruth/powerpoint_run_hyperlink.pptx.itxt
  • added tests/data/pptx/groundtruth/powerpoint_run_hyperlink.pptx.json
  • added tests/data/pptx/groundtruth/powerpoint_run_hyperlink.pptx.md

Assessment: expected. The PR intentionally changes body text from the paragraph label to the text label. The reference counts show this: paragraph goes to 0 and text goes up by the same amount in each file. The new powerpoint_run_hyperlink.pptx reference files match the new fixture.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

ceberam
ceberam previously approved these changes Oct 8, 2026
@avanish-garg
avanish-garg force-pushed the fix/pptx-drops-hyperlinks-and-formatting branch from 0d3aed1 to 2513684 Compare October 9, 2026 06:12
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Oct 9, 2026
@avanish-garg
avanish-garg requested a review from ceberam October 9, 2026 07:53

@ceberam ceberam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avanish-garg I've just seen a blocking issue and added a couple of suggestions worth addressing.

Comment thread docling/backend/mspowerpoint_backend.py Resolved
Comment thread docling/backend/mspowerpoint_backend.py Resolved
@PeterStaar-IBM

Copy link
Copy Markdown
Member

Hi @avanish-garg, thank you for this pull request.

It has a merge conflict with main. Please rebase your branch on the latest main and resolve the conflict:

git fetch upstream
git rebase upstream/main
# resolve the conflicts, then:
git push --force-with-lease

We can continue with the review and CI after that.

@vagenas

vagenas commented Nov 4, 2026

Copy link
Copy Markdown
Member

@avanish-garg a heads-up for your rebase: since #3891 and docling-core 2.106.0, serializers join InlineGroup runs with no separator. Runs should keep their source whitespace, including whitespace-only runs between other runs, and only the outer edges of the block are trimmed. trim_run_edges in docling/utils/_inline_runs.py does this trim. Please check the new run paths against this.

The goldens also need regenerating. For example, a [Python library](...) with has two spaces on each side because of the old join, and I expect one space with the new core.

@avanish-garg
avanish-garg force-pushed the fix/pptx-drops-hyperlinks-and-formatting branch from 450cdac to 71f365f Compare November 11, 2026 15:55
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Nov 11, 2026
@avanish-garg
avanish-garg force-pushed the fix/pptx-drops-hyperlinks-and-formatting branch from 71f365f to 55c336c Compare November 26, 2026 09:01
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Nov 26, 2026
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>
@avanish-garg
avanish-garg force-pushed the fix/pptx-drops-hyperlinks-and-formatting branch from 55c336c to 2955915 Compare December 3, 2026 08:38
@avanish-garg

Copy link
Copy Markdown
Author

@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
ceberam previously approved these changes Dec 3, 2026

@ceberam ceberam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, because python-pptx resolves an internal relationship to a part name. A run link now keeps only the HYPERLINK and OPEN_FILE actions, the same rule _shape_hyperlink follows 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:hlinkClick link 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 🚀

@ceberam
ceberam force-pushed the fix/pptx-drops-hyperlinks-and-formatting branch from d8ef998 to 5b67b74 Compare December 3, 2026 12:45
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Dec 3, 2026
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>
@ceberam
ceberam force-pushed the fix/pptx-drops-hyperlinks-and-formatting branch from 5b67b74 to cb0e19e Compare December 3, 2026 17:48
@github-actions github-actions Bot removed the ai:ci-safe AI triage found no CI-safety concern (advisory) label Dec 3, 2026
@github-actions github-actions Bot added the ai:ci-safe AI triage found no CI-safety concern (advisory) label Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working pptx issue related to pptx backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PPTX backend drops every run-level hyperlink and character formatting (bold/italic/underline)

6 participants