
    ,h%                    H   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZmZ ddlmZ ddlmZmZmZmZ dd	lmZ erdd
lmZmZ ddlmZ ddlmZ  G d de      Z G d de      Z  G d de      Z! G d de      Z" G d de      Z# G d de      Z$ G d d      Z%y)z3Custom element classes related to text runs (CT_R).    )annotations)TYPE_CHECKINGCallableIteratorList)
CT_Drawing)qn)
ST_BrClear	ST_BrType)CT_RPr)BaseOxmlElementOptionalAttribute
ZeroOrMore	ZeroOrOne)TextAccumulator)	CT_Anchor	CT_InlineCT_LastRenderedPageBreak)
CT_TabStopc                  b   e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<    ed      Zded<    ed      Z ed      Z	 ed      Z
 ed      Z ed      ZddZd dZd!dZed"d       Zed#d       Zed$d       Zej(                  d%d       Zed&d       Zej(                  d'd       Zd(dZy))CT_Rz>`<w:r>` element, containing the properties and text for a run.zCallable[[], CT_Br]add_brzCallable[[], CT_TabStop]add_tabzCallable[[], CT_RPr]get_or_add_rPrzCallable[[], CT_Drawing]_add_drawingzCallable[..., CT_Text]_add_tzw:rPrzCT_RPr | NonerPrzw:brzw:crz	w:drawingzw:tzw:tabc                    | j                  |      }t        |j                               t        |      k  r|j                  t	        d      d       |S )z7Return a newly added `<w:t>` element containing `text`.textz	xml:spacepreserve)r   lenstripsetr	   )selfr!   ts      T/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/docx/oxml/text/run.pyadd_tz
CT_R.add_t'   s@    KKTK"tzz|s4y(EE"[/:.    c                H    | j                         }|j                  |       |S )zReturn newly appended `CT_Drawing` (`w:drawing`) child element.

        The `w:drawing` element has `inline_or_anchor` as its child.
        )r   append)r&   inline_or_anchordrawings      r(   add_drawingzCT_R.add_drawing.   s$    
 ##%'(r*   c                R    | j                  d      D ]  }| j                  |        y)z>Remove all child elements except a `w:rPr` element if present.z./*[not(self::w:rPr)]N)xpathremove)r&   es     r(   clear_contentzCT_R.clear_content7   s(     34 	AKKN	r*   c                X     ddl m t               d fd}t         |             S )zGText of run, possibly punctuated by `w:lastRenderedPageBreak` elements.r   r   c               3    K   j                  d      D ]K  } t        | t        f      rj                         E d {    |  2j	                  t        |              M j                         E d {    y 7 >7 w)NzZw:br | w:cr | w:drawing | w:lastRenderedPageBreak | w:noBreakHyphen | w:ptab | w:t | w:tab)r1   
isinstancer   poppushstr)r3   r   accumr&   s    r(   
iter_itemsz,CT_R.inner_content_items.<locals>.iter_itemsD   sv     ZZ	 ' a*.F!GH$yy{**GJJs1v&'" yy{"" + #s!   :B A<8B 6A>7B >B )returnz5Iterator[str | CT_Drawing | CT_LastRenderedPageBreak])docx.oxml.text.pagebreakr   r   list)r&   r<   r   r;   s   ` @@r(   inner_content_itemszCT_R.inner_content_items=   s%     	F!	#( JL!!r*   c                $    | j                  d      S )z7All `w:lastRenderedPageBreaks` descendants of this run.z./w:lastRenderedPageBreak)r1   r&   s    r(   lastRenderedPageBreakszCT_R.lastRenderedPageBreaksZ   s     zz566r*   c                8    | j                   }|y|j                  S )zxString contained in `w:val` attribute of `w:rStyle` grandchild.

        |None| if that element is not present.
        N)r   styler&   r   s     r(   rE   z
CT_R.style_   s     hh;yyr*   c                2    | j                         }||_        y)zuSet character style of this `w:r` element to `style`.

        If `style` is None, remove the style element.
        N)r   rE   )r&   rE   r   s      r(   rE   z
CT_R.stylej   s     !!#	r*   c                P    dj                  d | j                  d      D              S )zThe textual content of this run.

        Inner-content child elements like `w:tab` are translated to their text
        equivalent.
         c              3  2   K   | ]  }t        |        y wN)r:   ).0r3   s     r(   	<genexpr>zCT_R.text.<locals>.<genexpr>z   s      
CF
s   z4w:br | w:cr | w:noBreakHyphen | w:ptab | w:t | w:tab)joinr1   rB   s    r(   r!   z	CT_R.texts   s,     ww 
 JJ']^
 
 	
r*   c                P    | j                          t        j                  | |       y rK   )r4   _RunContentAppenderappend_to_run_from_textr&   r!   s     r(   r!   z	CT_R.text~   s    33D$?r*   c                *    | j                  d|       |S )Nr   )insertrF   s     r(   _insert_rPrzCT_R._insert_rPr   s    As
r*   N)r!   r:   r=   CT_Text)r-   zCT_Inline | CT_Anchorr=   r   )r=   None)r=   z1List[str | CT_Drawing | CT_LastRenderedPageBreak])r=   zList[CT_LastRenderedPageBreak])r=   
str | None)rE   rX   r=   r:   r!   r:   )r   r   r=   r   )__name__
__module____qualname____doc____annotations__r   r   r   brcrr.   r'   tabr)   r/   r4   propertyr@   rC   rE   setterr!   rU    r*   r(   r   r      s    H%%((**"""7+C+	F	B	F	B%G5A
W
C " "8 7 7   \\  
 
 
[[@ @r*   r   c                  V    e Zd ZU dZ eded      Zded<    ede      Z	ded<   dd	Z
y
)CT_BrzD`<w:br>` element, indicating a line, page, or column break in a run.zw:typetextWrapping)defaultrX   typezw:clearclearc                (    | j                   dk(  rdS dS )a>  Text equivalent of this element. Actual value depends on break type.

        A line break is translated as "
". Column and page breaks produce the empty
        string ("").

        This allows the text of run inner-content to be accessed in a consistent way
        for all run inner-context text elements.
        rh   
rI   )rj   rB   s    r(   __str__zCT_Br.__str__   s     yyN2t::r*   NrY   )r[   r\   r]   r^   r   r   rj   r_   r
   rk   rn   re   r*   r(   rg   rg      s5    N()^D*  *)Z@E:@	;r*   rg   c                      e Zd ZdZddZy)CT_Cra<  `<w:cr>` element, representing a carriage-return (0x0D) character within a run.

    In Word, this represents a "soft carriage-return" in the sense that it does not end
    the paragraph the way pressing Enter (aka. Return) on the keyboard does. Here the
    text equivalent is considered to be newline ("
") since in plain-text that's the
    closest Python equivalent.

    NOTE: this complex-type name does not exist in the schema, where `w:tab` maps to
    `CT_Empty`. This name was added to give it distinguished behavior. CT_Empty is used
    for many elements.
    c                     y)z8Text equivalent of this element, a single newline ("
").rm   re   rB   s    r(   rn   zCT_Cr.__str__   s    r*   NrY   r[   r\   r]   r^   rn   re   r*   r(   rp   rp      s    
r*   rp   c                      e Zd ZdZddZy)CT_NoBreakHyphenah  `<w:noBreakHyphen>` element, a hyphen ineligible for a line-wrap position.

    This maps to a plain-text dash ("-").

    NOTE: this complex-type name does not exist in the schema, where `w:noBreakHyphen`
    maps to `CT_Empty`. This name was added to give it behavior distinguished from the
    many other elements represented in the schema by CT_Empty.
    c                     y)z?Text equivalent of this element, a single dash character ("-").-re   rB   s    r(   rn   zCT_NoBreakHyphen.__str__   s    r*   NrY   rr   re   r*   r(   rt   rt      s    r*   rt   c                      e Zd ZdZddZy)CT_PTaba  `<w:ptab>` element, representing an absolute-position tab character within a run.

    This character advances the rendering position to the specified position regardless
    of any tab-stops, perhaps for layout of a table-of-contents (TOC) or similar.
    c                     y)zText equivalent of this element, a single tab ("	") character.

        This allows the text of run inner-content to be accessed in a consistent way
        for all run inner-context text elements.
        	re   rB   s    r(   rn   zCT_PTab.__str__   s     r*   NrY   rr   re   r*   r(   rx   rx      s    r*   rx   c                      e Zd ZdZddZy)rV   zB`<w:t>` element, containing a sequence of characters within a run.c                "    | j                   xs dS )a@  Text contained in this element, the empty string if it has no content.

        This property allows this run inner-content element to be queried for its text
        the same way as other run-content elements are. In particular, this never
        returns None, as etree._Element does when there is no content.
        rI   r    rB   s    r(   rn   zCT_Text.__str__   s     yyBr*   NrY   rr   re   r*   r(   rV   rV      s
    Lr*   rV   c                  @    e Zd ZdZddZed	d       Zd
dZddZd Z	y)rP   af  Translates a Python string into run content elements appended in a `w:r` element.

    Contiguous sequences of regular characters are appended in a single `<w:t>` element.
    Each tab character ('	') causes a `<w:tab/>` element to be appended. Likewise a
    newline or carriage return character ('
', '') causes a `<w:cr>` element to be
    appended.
    c                     || _         g | _        y rK   )_r_bfr)r&   rs     r(   __init__z_RunContentAppender.__init__   s    !	r*   c                6     | |      }|j                  |       y)z8Append inner-content elements for `text` to `r` element.N)add_text)clsr   r!   appenders       r(   rQ   z+_RunContentAppender.append_to_run_from_text   s     q6$r*   c                T    |D ]  }| j                  |        | j                          y)z>Append inner-content elements for `text` to the `w:r` element.N)add_charflush)r&   r!   chars      r(   r   z_RunContentAppender.add_text   s&     	 DMM$	 

r*   c                    |dk(  r+| j                          | j                  j                          y|dv r+| j                          | j                  j                          y| j                  j                  |       y)a0  Process next character of input through finite state maching (FSM).

        There are two possible states, buffer pending and not pending, but those are
        hidden behind the `.flush()` method which must be called at the end of text to
        ensure any pending `<w:t>` element is written.
        rz   z
N)r   r   r   r   r   r,   )r&   r   s     r(   r   z_RunContentAppender.add_char   sR     4<JJLGGOOV^JJLGGNNIIT"r*   c                    dj                  | j                        }|r| j                  j                  |       | j                  j	                          y )NrI   )rN   r   r   r)   rk   rR   s     r(   r   z_RunContentAppender.flush  s5    wwtyy!GGMM$		r*   N)r   r   )r   r   r!   r:   rZ   )r   r:   )
r[   r\   r]   r^   r   classmethodrQ   r   r   r   re   r*   r(   rP   rP      s/    "    
# r*   rP   N)&r^   
__future__r   typingr   r   r   r   docx.oxml.drawingr   docx.oxml.nsr	   docx.oxml.simpletypesr
   r   docx.oxml.text.fontr   docx.oxml.xmlchemyr   r   r   r   docx.sharedr   docx.oxml.shaper   r   r>   r   docx.oxml.text.parfmtr   r   rg   rp   rt   rx   rV   rP   re   r*   r(   <module>r      s    9 " : : (  7 & X X '4A0n? nj;O ;(O $ o *
o 
"- -r*   