Xj+XdZddlmZddlmZmZmZmZmZddl m Z ddl m Z ddl mZddlmZmZddlmZdd lmZmZmZmZdd lmZerdd lmZmZdd lmZdd l m!Z!GddeZ"GddeZ#GddeZ$GddeZ%GddeZ&GddeZ'GddZ(y)z3Custom element classes related to text runs (CT_R).) annotations) TYPE_CHECKINGCallableIteratorListcast) CT_Drawing)qn) OxmlElement) ST_BrClear ST_BrType)CT_RPr)BaseOxmlElementOptionalAttribute ZeroOrMore ZeroOrOne)TextAccumulator) CT_Anchor CT_InlineCT_LastRenderedPageBreak) CT_TabStopczeZdZUdZded<ded<ded<ded <d ed <ed Zd ed<edZedZ edZ edZ edZ d"dZ d#dZd$dZed%dZd&dZd&dZed'dZed(dZej,d)dZed*dZej,d+dZd,dZd-d Zy!).CT_Rz>`` element, containing the properties and text for a run.zCallable[[], CT_Br]add_brzCallable[[], CT_TabStop]add_tabzCallable[[], CT_RPr]get_or_add_rPrzCallable[[], CT_Drawing] _add_drawingzCallable[..., CT_Text]_add_tzw:rPrz CT_RPr | NonerPrzw:brzw:crz w:drawingzw:tzw:tabc|j|}t|jt|kr|jt dd|S)z7Return a newly added `` element containing `text`.textz xml:spacepreserve)rlenstripsetr )selfr#ts f/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/oxml/text/run.pyadd_tz CT_R.add_t(s@ KKTK " tzz| s4y ( EE"[/: .cH|j}|j||S)zReturn newly appended `CT_Drawing` (`w:drawing`) child element. The `w:drawing` element has `inline_or_anchor` as its child. )rappend)r(inline_or_anchordrawings r* add_drawingzCT_R.add_drawing/s$ ##%'(r,cR|jdD]}|j|y)z>Remove all child elements except a `w:rPr` element if present.z./*[not(self::w:rPr)]N)xpathremove)r(es r* clear_contentzCT_R.clear_content8s(34 A KKN r,cXddlmtdfd }t|S)zGText of run, possibly punctuated by `w:lastRenderedPageBreak` elements.rrc3KjdD]K}t|tfrjEd{|2j t |MjEd{y7>7w)NzZw:br | w:cr | w:drawing | w:lastRenderedPageBreak | w:noBreakHyphen | w:ptab | w:t | w:tab)r3 isinstancer poppushstr)r5raccumr(s r* iter_itemsz,CT_R.inner_content_items..iter_itemsEsvZZ  'a*.F!GH$yy{**GJJs1v& '"yy{ " " + #s!:BA<8B6A>7B>B)returnz5Iterator[str | CT_Drawing | CT_LastRenderedPageBreak])docx.oxml.text.pagebreakrrlist)r(r>rr=s` @@r*inner_content_itemszCT_R.inner_content_items>s% F! #(JL!!r,c |j|j||jtdtdt |iy)zInsert a `w:commentRangeEnd` and `w:commentReference` element after this run. The `w:commentRangeEnd` element is the immediate sibling of this `w:r` and is followed by a `w:r` containing the `w:commentReference` element. zw:commentRangeEndw:idattrsN)addnext_new_comment_reference_runr r r<r( comment_ids r*,insert_comment_range_end_and_reference_belowz1CT_R.insert_comment_range_end_and_reference_below[s< T44Z@A [!4RZZzCT_R.text..s CF sz4w:br | w:cr | w:noBreakHyphen | w:ptab | w:t | w:tab)joinr3rPs r*r#z CT_R.texts,ww  JJ']^   r,cP|jtj||yrY)r6_RunContentAppenderappend_to_run_from_textr(r#s r*r#z CT_R.texts 33D$?r,c*|jd||S)Nr)insertrTs r* _insert_rPrzCT_R._insert_rPrs As r,c tttd}|j}d|_|j tdt dt|i|S)a Return a new `w:r` element with `w:commentReference` referencing `comment_id`. Should look like this: zw:rCommentReferencezw:commentReferencerDrE)rrr rrSr.r r<)r(rJrr s r*rHzCT_R._new_comment_reference_runsP {5) * &  1"V*c*o9VWXr,N)r#r<r?CT_Text)r/zCT_Inline | CT_Anchorr?r )r?None)r?z1List[str | CT_Drawing | CT_LastRenderedPageBreak])rJintr?rh)r?zList[CT_LastRenderedPageBreak])r? str | None)rSrjr?r<r#r<)r rr?r)rJrir?r)__name__ __module__ __qualname____doc____annotations__rr rbrcrr0r)tabr+r1r6propertyrBrKrNrQrSsetterr#rcrHr,r*rrs H  %%((** """7+C+ F B F B%G5A W C ""8\b77 \\   [[@@r,rcVeZdZUdZededZded<edeZ ded<d d Z y ) CT_BrzD`` element, indicating a line, page, or column break in a run.zw:type textWrapping)defaultrjtypezw:clearclearc(|jdk(rdSdS)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. rz rW)r|rPs r*__str__z CT_Br.__str__syyN2t::r,Nrk) rmrnrorprr r|rqr r}rrwr,r*ryrys5N()^D**)Z@E:@ ;r,ryceZdZdZddZy)CT_Cra<`` 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. cy)z8Text equivalent of this element, a single newline (" ").rrwrPs r*rz CT_Cr.__str__sr,Nrkrmrnrorprrwr,r*rrs  r,rceZdZdZddZy)CT_NoBreakHyphenah`` 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. cy)z?Text equivalent of this element, a single dash character ("-").-rwrPs r*rzCT_NoBreakHyphen.__str__sr,Nrkrrwr,r*rrs r,rceZdZdZddZy)CT_PTaba`` 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. cy)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.  rwrPs r*rzCT_PTab.__str__s r,Nrkrrwr,r*rrs  r,rceZdZdZddZy)rgzB`` element, containing a sequence of characters within a run.c"|jxsdS)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. rWr"rPs r*rzCT_Text.__str__syyBr,Nrkrrwr,r*rgrgs Lr,rgc@eZdZdZddZed dZd dZd dZdZ y) r^afTranslates a Python string into run content elements appended in a `w:r` element. Contiguous sequences of regular characters are appended in a single `` element. Each tab character (' ') causes a `` element to be appended. Likewise a newline or carriage return character (' ', ' ') causes a `` element to be appended. c ||_g|_yrY)_r_bfr)r(rfs r*__init__z_RunContentAppender.__init__s! r,c6||}|j|y)z8Append inner-content elements for `text` to `r` element.N)add_text)clsrfr#appenders r*r_z+_RunContentAppender.append_to_run_from_textsq6$r,cT|D]}|j||jy)z>Append inner-content elements for `text` to the `w:r` element.N)add_charflush)r(r#chars r*rz_RunContentAppender.add_texts& D MM$   r,c|dk(r+|j|jjy|dvr+|j|jjy|jj |y)a0Process 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 `` element is written. rz N)rrrrrr.)r(rs r*rz_RunContentAppender.add_charsR 4< JJL GGOO  V^ JJL GGNN  II  T "r,cdj|j}|r|jj||jj y)NrW)r\rrr+r}r`s r*rz_RunContentAppender.flush/s5wwtyy!  GGMM$  r,N)rfr)rfrr#r<rl)rr<) rmrnrorpr classmethodr_rrrrwr,r*r^r^s/"   # r,r^N))rp __future__rtypingrrrrrdocx.oxml.drawingr docx.oxml.nsr docx.oxml.parserr docx.oxml.simpletypesr r docx.oxml.text.fontrdocx.oxml.xmlchemyrrrr docx.sharedrdocx.oxml.shaperrr@rdocx.oxml.text.parfmtrrryrrrrgr^rwr,r*rs9"@@((7&XX'4A0 L?Lf;O;(O$   o * o "--r,