Repository navigation
fix(docx): keep hyperlink runs nested in a wrapper - #4576
Merged
PeterStaar-IBM merged 1 commit intoOct 5, 2026
Merged
Conversation
python-docx's Hyperlink.text and Hyperlink.runs only read the direct w:r children of a w:hyperlink, so text in a tracked insertion, smart tag, custom XML or simple field inside the link was dropped. Read the hyperlink's runs through the same wrappers that paragraph runs already go through. Resolves docling-project#4575 Signed-off-by: Yuilona <143536279+Yuilona@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
✅ DCO Check Passed Thanks @Yuilona, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
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.
The Word backend dropped hyperlink text that sits in a wrapper inside the
w:hyperlink. A tracked insertion made inside link text (<w:hyperlink><w:ins><w:r>…) is the common case, and smart tags, custom XML and simple fields behave the same way._iter_paragraph_contentalready reads runs insidew:ins,w:smartTag,w:customXmlandw:fldSimplewhen they wrap runs directly in the paragraph. A hyperlink's text, however, came from python-docx'sHyperlink.text, and its formatting fromHyperlink.runs. Both only read the directw:rchildren (CT_Hyperlink.textis"".join(r.text for r in self.xpath("w:r"))). This PR collects the hyperlink's runs with the same_get_children_recursivehelper, so text and formatting come from all of its runs, in document order. The hyperlink target is unchanged.<w:hyperlink>content[the ]<w:ins>[docs]</w:ins>thethe docs<w:smartTag>[docs]</w:smartTag>docs<w:customXml>[docs]</w:customXml>docs<w:fldSimple>[docs]</w:fldSimple>docsThis touches a different part of
_iter_paragraph_contentfrom #4369, which addsmoveTo,dirandbdoto the paragraph-level wrappers. Once both are in, those wrappers will be read inside hyperlinks too. #4455 covers wrapped runs in plain table cells, which take a separate path.Issue resolved by this Pull Request:
Resolves #4575
Testing (Linux, Python 3.11):
test_hyperlink_keeps_runs_nested_in_a_wrapper, parametrized over the four wrappers. It checks that the link item readsthe docsand keeps itshttps://example.com/target. All four cases fail onmainand pass with the change.tests/test_backend_msword.pypasses, and the DOCX ground-truth files are unchanged.test_email_backend_collapses_line_breaks_in_headers, fails the same way onmainin my environment.ruff formatandruff checkare clean.ty checkon the file gives the same diagnostics as onmain.Checklist:
Disclosure: this PR is AI-assisted. Claude Code found the bug while converting randomly generated DOCX files and checking that every word survived, then wrote the fix and the tests and ran the checks above.
🤖 Generated with Claude Code