feat: Page break insert and delete API#42
Conversation
Add `Paragraph.add_page_break()`, `Paragraph.has_page_break`, and `Paragraph.clear_page_breaks()` methods for high-level page break management. Update `Document.add_page_break()` to delegate to the new paragraph method. Closes #20 Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Security Agent Report SECURITY_PASS Security Review: PR #42 — Page Break Insert/Delete APIBranch: agent/issue-20 SummaryNo security issues found. All changes are internal refactoring and new paragraph-level page break methods with no exposure to external input. Files Reviewed
ChecksInjection Risks (XPath / XXE / XML injection)The two new XPath queries in self._p.xpath('.//w:br[@w:type="page"]') # lines 83, 98
Path Traversal / File HandlingNo file paths or file I/O in the changed code. New DependenciesNo new dependencies added ( Secrets / CredentialsNo API keys, tokens, passwords, or other secrets present. Data ExposureNo sensitive data is read, logged, or returned. The methods operate entirely on the in-memory lxml element tree. Notes (Non-Security)One pre-existing pattern (outside this PR's scope) in comment_elms = self.xpath(f"(./w:comment[@w:id='{comment_id}'])[1]")This is not part of PR #42 but may warrant a follow-up review: if Result: PASS — no security issues in this PR. |
|
Security Agent Report SECURITY_PASS Security Review — PR #42SummaryPR #42 adds Files Reviewed
FindingsNo issues found.XPath expressions ( XML manipulation ( No new dependencies introduced. No file I/O or path handling added. No secrets, credentials, or sensitive data present in any changed file. ConclusionAll changes are safe, well-scoped DOM manipulations with hardcoded XPath expressions. No security concerns identified. |
|
Review Agent REVIEW_APPROVED SummaryClean, correct refactoring that moves page-break logic to the right abstraction level ( What's good
Minor observations (not blocking)
|
Summary
Implements #20
This PR was automatically generated by the Developer Agent.
Original Issue
Feature Description
python-docx currently supports adding a page break only by appending a
w:brelement to a run (run.add_break(WD_BREAK.PAGE)). This is low-level, requires the caller to manage run/paragraph structure manually, and provides no way to insert a page break at an arbitrary position within the document or to delete an existing one.This issue adds a clean high-level API for inserting and deleting page breaks anywhere in the document, consistent with the existing
Document.add_paragraph()/Document.add_section()patterns.Acceptance Criteria
Insertion
paragraph.add_page_break()inserts a page break at the end of the given paragraph (appends a run containing<w:br w:type="page"/>)document.add_page_break()inserts a new paragraph containing a page break at the end of the document body and returns the paragraphParagraphobject containing the break so the caller can chain further operationsDeletion
paragraph.clear_page_breaks()removes all<w:br w:type="page"/>runs from the paragraphparagraph.has_page_break(bool property) allows callers to detect whether a paragraph contains a page break before deciding to delete it<w:br>element is removedEdge cases
Suggested Implementation
docx/text/paragraph.py— add toParagraph:docx/document.py— add toDocument:Tests — add to
tests/unit/text/test_paragraph.pyandtests/unit/test_document.py:has_page_breakreturns True/False correctlyclear_page_breaksremoves only<w:br type="page">elements, leaves text runs intactDependencies
None.
Out of Scope
WD_BREAK.COLUMN) — separate issueWD_BREAK.TEXT_WRAPPING) — separate issueGenerated by Developer Agent using Claude Code