Skip to content

Fix rendered page break fragments adjacent to hyperlinks - #1625

Open
kokotatan wants to merge 1 commit into
python-openxml:masterfrom
kokotatan:fix-page-break-adjacent-hyperlinks
Open

kokotatan wants to merge 1 commit into
python-openxml:masterfrom
kokotatan:fix-page-break-adjacent-hyperlinks

Conversation

@kokotatan

Copy link
Copy Markdown

RenderedPageBreak.preceding_paragraph_fragment and following_paragraph_fragment can return None when the paragraph still contains a hyperlink on that side of the break. For example, a hyperlink followed by a run that starts with a rendered page break loses the hyperlink during page-by-page text extraction.

The boundary checks currently consider only direct w:r children. Include w:hyperlink when selecting the first/last paragraph content element, matching CT_P.inner_content_elements. Fragment construction itself already preserves hyperlinks.

Four regression cases cover links before and after the break, with and without non-content siblings. They check the extracted text, hyperlink anchor, and that the original paragraph XML is unchanged. All four fail on the unmodified source and pass with this fix.

Validation on Windows / Python 3.12.12:

  • pytest -q: 1,613 passed.
  • behave --format progress --stop --tags=-wip: 67 features / 650 scenarios passed.
  • ruff check . and formatting checks for both changed files passed.
  • Source distribution and wheel built successfully.
  • Pyright reports the same 7,588 existing diagnostics on the original and patched source (compared by file, severity, rule, and message); no diagnostics were added or removed.

Local test setup uses pytest 8.4.2 and pyparsing 3.2.5, and LF fixture/template files. Dependency and line-ending adjustments are not included in this change. The declared lxml type stubs are installed for the type comparison.

AI assistance was used to investigate, implement, test, and review this change.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant