Xj+rdZddlmZddlZddlmZddlmZddlm Z er ddl m Z ddl m Z Gd d eZy) zHCustom element class for rendered page-break (CT_LastRenderedPageBreak).) annotationsN) TYPE_CHECKING)BaseOxmlElement) lazyproperty) CT_Hyperlink)CT_PceZdZdZeddZeddZeddZeddZddZ eddZ ddZ e dd Z e dd Ze dd Ze dd Ze dd Ze ddZy)CT_LastRenderedPageBreaka`` element, indicating page break inserted by renderer. A rendered page-break is one inserted by the renderer when it runs out of room on a page. It is an empty element (no attrs or children) and is a child of CT_R, peer to CT_Text. NOTE: this complex-type name does not exist in the schema, where `w:lastRenderedPageBreak` maps to `CT_Empty`. This name was added to give it distinguished behavior. CT_Empty is used for many elements. c||j|jk(s td|jr |jS|j S)aA "loose" `CT_P` containing only the paragraph content before this break. Raises `ValueError` if this `w:lastRenderedPageBreak` is not the first rendered page-break in its paragraph. The returned `CT_P` is a "clone" (deepcopy) of the `w:p` ancestor of this page-break with this `w:lastRenderedPageBreak` element and all content preceding it removed. NOTE: this `w:p` can itself contain one or more `w:renderedPageBreak` elements (when the paragraph contained more than one). While this is rare, the caller should treat this paragraph the same as other paragraphs and split it if necessary in a folloing step or recursion. 6only defined on first rendered page-break in paragraph)_first_lrpb_in_p _enclosing_p ValueError_is_in_hyperlink_following_frag_in_hlink_following_frag_in_runselfs l/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/oxml/text/pagebreak.pyfollowing_fragment_pz-CT_LastRenderedPageBreak.following_fragment_psO t,,T->->??UV V.2-B-BD ) ) HLHcHc c|jryt|jjd|jdS)zTrue when this page-break element is the last "content" in the paragraph. This is very uncommon case and may only occur in contrived or cases where the XML is edited by hand, but it is not precluded by the spec. FzA(./w:r)[last()]/w:lastRenderedPageBreak[not(following-sibling::*[])]rboolrxpath_run_inner_content_xpathrs rfollows_all_contentz,CT_LastRenderedPageBreak.follows_all_content4sL      # #-.2-J-J,K3 P   rc|jryt|jjd|jdS)zTrue when a `w:lastRenderedPageBreak` precedes all paragraph content. This is a common case; it occurs whenever the page breaks on an even paragraph boundary. Fz:./w:r[1]/w:lastRenderedPageBreak[not(preceding-sibling::*[rrrs rprecedes_all_contentz-CT_LastRenderedPageBreak.precedes_all_contentMsL      # #-.2-J-J,K3 P   rc||j|jk(s td|jr |jS|j S)aA "loose" `CT_P` containing only the paragraph content before this break. Raises `ValueError` if this `w:lastRenderedPageBreak` is not the first rendered paragraph in its paragraph. The returned `CT_P` is a "clone" (deepcopy) of the `w:p` ancestor of this page-break with this `w:lastRenderedPageBreak` element and all its following siblings removed. r )r rrr_preceding_frag_in_hlink_preceding_frag_in_runrs rpreceding_fragment_pz-CT_LastRenderedPageBreak.preceding_fragment_pesOt,,T->->??UV V.2-B-BD ) ) HLHcHc rc*|jddS)zThe `w:hyperlink` grandparent of this `w:lastRenderedPageBreak`. Raises `IndexError` when this page-break has a `w:p` grandparent, so only call when `._is_in_hyperlink` is True. !./parent::w:r/parent::w:hyperlinkrr)rlrpbs r_enclosing_hyperlinkz-CT_LastRenderedPageBreak._enclosing_hyperlinkxs zz=>qAArc*|jddS)zJThe `w:p` element parent or grandparent of this `w:lastRenderedPageBreak`.z./ancestor::w:p[1]rr'rs rrz%CT_LastRenderedPageBreak._enclosing_pszz./22rcH|jd}|s td|dS)zThe first `w:lastRenderedPageBreak` element in `p`. Raises `ValueError` if there are no rendered page-breaks in `p`. zI./w:r/w:lastRenderedPageBreak | ./w:hyperlink/w:r/w:lastRenderedPageBreakz,no rendered page-breaks in paragraph elementr)rr)rplrpbss rr z)CT_LastRenderedPageBreak._first_lrpb_in_ps+ cdKL LQxrcB|js tdtj|j}|j |}|j |}|jdD]}|j||jj||S)zFollowing CT_P fragment when break occurs within a hyperlink. Note this is a *partial-function* and raises when `lrpb` is not inside a hyperlink. 4only defined on a rendered page-break in a hyperlink(./preceding-sibling::*[not(self::w:pPr)] rrcopydeepcopyrr r)rremove getparentrr,r( hyperlinkes rrz1CT_LastRenderedPageBreak._following_frag_in_hlinks$$ST T MM$++ ,$$Q'--d3 !KL A HHQK  $$Y/rcz|jr tdtj|j}|j |}|j dd}|j dD]}|j||j dD]}|j||j||S)zfollowing CT_P fragment when break does not occur in a hyperlink. Note this is a *partial-function* and raises when `lrpb` is inside a hyperlink. 8only defined on a rendered page-break not in a hyperlink ./parent::w:rrr0z(./preceding-sibling::*[not(self::w:rPr)]rrr2r3rr rr4rr,r( enclosing_rr8s rrz/CT_LastRenderedPageBreak._following_frag_in_runs  WX X MM$++ ,$$Q'jj1!4 ""#MN A HHQK  FG "A   q ! "4 rc6t|jdS)z9True when this page-break is embedded in a hyperlink run.r&)rrrs rrz)CT_LastRenderedPageBreak._is_in_hyperlinksDJJBCDDrcB|js tdtj|j}|j |}|j |}|jdD]}|j||jj||S)zPreceding CT_P fragment when break occurs within a hyperlink. Note this is a *partial-function* and raises when `lrpb` is not inside a hyperlink. r/./following-sibling::*r1r6s rr"z1CT_LastRenderedPageBreak._preceding_frag_in_hlinks$$ST T MM$++ ,$$Q'--d3 !9: A HHQK  %rcz|jr tdtj|j}|j |}|j dd}|j dD]}|j||j dD]}|j||j||S)zPreceding CT_P fragment when break does not occur in a hyperlink. Note this is a *partial-function* and raises when `lrpb` is inside a hyperlink. r:r;rrAr<r=s rr#z/CT_LastRenderedPageBreak._preceding_frag_in_runs  WX X MM$++ ,$$Q'jj1!4 ""#;< A HHQK  45 "A   q ! "4 rc y)z7XPath fragment matching any run inner-content elements.zjself::w:br | self::w:cr | self::w:drawing | self::w:noBreakHyphen | self::w:ptab | self::w:t | self::w:tabrs rrz1CT_LastRenderedPageBreak._run_inner_content_xpath s   rN)returnr)rEr)r(r rEr)r,rrEr )rEstr)__name__ __module__ __qualname____doc__propertyrrr r$r)rr rrrrr"r#rrDrrr r s   .  0  .  $B338:EE::    rr )rJ __future__rr2typingrdocx.oxml.xmlchemyr docx.sharedrdocx.oxml.text.hyperlinkrdocx.oxml.text.paragraphrr rDrrrRs.N" .$5-F F r