
    ,h+                    r    d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 erddl
mZ ddlmZ  G d	 d
e      Zy)zHCustom element class for rendered page-break (CT_LastRenderedPageBreak).    )annotationsN)TYPE_CHECKING)BaseOxmlElement)lazyproperty)CT_Hyperlink)CT_Pc                      e Zd ZdZedd       Zedd       Zedd       Zedd       ZddZ	edd       Z
ddZedd	       Zedd
       Zedd       Zedd       Zedd       Zedd       Zy)CT_LastRenderedPageBreaka  `<w:lastRenderedPageBreak>` 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                  | j                        k(  st        d      | j                  r| j                  S | j
                  S )a  A "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_runselfs    Z/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/docx/oxml/text/pagebreak.pyfollowing_fragment_pz-CT_LastRenderedPageBreak.following_fragment_p   sT      t,,T->->??UVV
 $$ ))	
 ,,	
    c                    | j                   ryt        | j                  j                  d| j                   d            S )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::*[])]r   boolr   xpath_run_inner_content_xpathr   s    r   follows_all_contentz,CT_LastRenderedPageBreak.follows_all_content6   sL       ##- .2-J-J,K3	P

 
	
r   c                    | j                   ryt        | j                  j                  d| j                   d            S )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::*[r   r   r   s    r   precedes_all_contentz-CT_LastRenderedPageBreak.precedes_all_contentO   sL       ##- .2-J-J,K3	P

 
	
r   c                    | | j                  | j                        k(  st        d      | j                  r| j                  S | j
                  S )a  A "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   r   r   r   _preceding_frag_in_hlink_preceding_frag_in_runr   s    r   preceding_fragment_pz-CT_LastRenderedPageBreak.preceding_fragment_pg   sT     t,,T->->??UVV
 $$ ))	
 ,,	
r   c                *    |j                  d      d   S )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:hyperlinkr   r   )r   lrpbs     r   _enclosing_hyperlinkz-CT_LastRenderedPageBreak._enclosing_hyperlink|   s     zz=>qAAr   c                *    | j                  d      d   S )zJThe `w:p` element parent or grandparent of this `w:lastRenderedPageBreak`.z./ancestor::w:p[1]r   r'   r   s    r   r   z%CT_LastRenderedPageBreak._enclosing_p   s     zz./22r   c                H    |j                  d      }|st        d      |d   S )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   )r   r   )r   plrpbss      r   r   z)CT_LastRenderedPageBreak._first_lrpb_in_p   s/    
 W
 KLLQxr   c                B   | j                   st        d      t        j                  | j                        }| j                  |      }|j                  |      }|j                  d      D ]  }|j                  |        |j                         j                  |       |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)]
r   r   copydeepcopyr   r   r)   r   remove	getparentr   r,   r(   	hyperlinkes        r   r   z1CT_LastRenderedPageBreak._following_frag_in_hlink   s     $$STT MM$++, $$Q' --d3	 !KL 	AHHQK	 	$$Y/ r   c                z   | j                   rt        d      t        j                  | j                        }| j                  |      }|j                  d      d   }|j                  d      D ]  }|j                  |        |j                  d      D ]  }|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:rr   r0   z(./preceding-sibling::*[not(self::w:rPr)]r   r   r2   r3   r   r   r   r4   r   r,   r(   enclosing_rr8   s        r   r   z/CT_LastRenderedPageBreak._following_frag_in_run   s       WXX MM$++, $$Q' jj1!4 ""#MN 	AHHQK	
 FG 	"Aq!	"4 r   c                6    t        | j                  d            S )z9True when this page-break is embedded in a hyperlink run.r&   )r   r   r   s    r   r   z)CT_LastRenderedPageBreak._is_in_hyperlink   s     DJJBCDDr   c                B   | j                   st        d      t        j                  | j                        }| j                  |      }|j                  |      }|j                  d      D ]  }|j                  |        |j                         j                  |       |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::*r1   r6   s        r   r"   z1CT_LastRenderedPageBreak._preceding_frag_in_hlink   s     $$STT MM$++, $$Q' --d3	 !9: 	AHHQK	 	% r   c                z   | j                   rt        d      t        j                  | j                        }| j                  |      }|j                  d      d   }|j                  d      D ]  }|j                  |        |j                  d      D ]  }|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;   r   rA   r<   r=   s        r   r#   z/CT_LastRenderedPageBreak._preceding_frag_in_run   s       WXX MM$++, $$Q' jj1!4 ""#;< 	AHHQK	
 45 	"Aq!	"4 r   c                     	 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:tab r   s    r   r   z1CT_LastRenderedPageBreak._run_inner_content_xpath  s    	
r   N)returnr   )rE   r   )r(   r
   rE   r   )r,   r   rE   r
   )rE   str)__name__
__module____qualname____doc__propertyr   r   r    r$   r)   r   r   r   r   r   r   r"   r#   r   rD   r   r   r
   r
      s    	 
 
2 
 
0 
 
. 
 
(B 3 3
  8  : E E  :  : 

 

r   r
   )rJ   
__future__r   r2   typingr   docx.oxml.xmlchemyr   docx.sharedr   docx.oxml.text.hyperlinkr   docx.oxml.text.paragraphr   r
   rD   r   r   <module>rR      s.    N "    . $5-L
 L
r   