+
    f0iD                        R t ^ RIHt ^ RIt^ RIHu Ht ^ RIHtH	t	 ^RI
Ht ^RI
Ht ]'       d   ^ RIHt R R ltR	 R
 lt ! R R]P"                  4      t ! R R]4      t ! R R]4      t ! R R]4      tR# )z
Tree processors manipulate the tree created by block processors. They can even create an entirely
new `ElementTree` object. This is an excellent place for creating summaries, adding collected
references, or last minute adjustments.

)annotationsN)TYPE_CHECKINGAny)util)inlinepatterns)Markdownc               $    V ^8  d   QhRRRRRR/# )   mdr   kwargsr   returnzutil.Registry[Treeprocessor] )formats   "]/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/markdown/treeprocessors.py__annotate__r   '   s"      X  9U     c                    \         P                  ! 4       pVP                  \        V 4      R^4       VP                  \	        V 4      R^
4       VP                  \        V 4      R^ 4       V# )z2Build the default  `treeprocessors` for Markdown. inlineprettifyunescape)r   RegistryregisterInlineProcessorPrettifyTreeprocessorUnescapeTreeprocessor)r
   r   treeprocessorss   &, r   build_treeprocessorsr   '   sZ    ]]_NOB/2>1"5z2F1"5z1Er   c                    V ^8  d   QhRRRR/# )r	   sobjectr   boolr   )r   s   "r   r   r   0   s       4 r   c                f    \        V \        P                  4      '       g   \        V \        4      # R# )z^Return `True` if object is a string but not an  [`AtomicString`][markdown.util.AtomicString]. F)
isinstancer   AtomicStringstr)r   s   &r   isStringr%   0   s%    a**++!S!!r   c                  &    ] tR t^7tRtR R ltRtR# )Treeprocessorz
`Treeprocessor`s are run on the `ElementTree` object before serialization.

Each `Treeprocessor` implements a `run` method that takes a pointer to an
`Element` and modifies it as necessary.

`Treeprocessors` must extend `markdown.Treeprocessor`.

c                    V ^8  d   QhRRRR/# )r	   rootetree.Elementr   etree.Element | Noner   )r   s   "r   r   Treeprocessor.__annotate__A   s       *> r   c                    R# )z
Subclasses of `Treeprocessor` should implement a `run` method, which
takes a root `Element`. This method can return another `Element`
object, and the existing root `Element` will be replaced, or it can
modify the current tree and return `None`.
Nr   )selfr)   s   &&r   runTreeprocessor.runA   s     	r   r   N)__name__
__module____qualname____firstlineno____doc__r/   __static_attributes__r   r   r   r'   r'   7   s     r   r'   c                      ] tR t^KtRtR R ltR R ltR R ltR R	 ltRR
 R llt	RR R llt
RR R lltRR R lltR R ltRR R lltRtR# )r   zD
A `Treeprocessor` that traverses a tree, applying inline patterns.
c                   V ^8  d   QhRR/# )r	   r
   r   r   )r   s   "r   r   InlineProcessor.__annotate__P   s     ' '8 'r   c                	6   \         P                  V n        \         P                  V n        ^\        V P                  4      ,           \        V P                  4      ,           V n        \         P                  V n        Wn	        VP                  V n
        . V n        R# )   N)r   INLINE_PLACEHOLDER_PREFIX$_InlineProcessor__placeholder_prefixETX$_InlineProcessor__placeholder_suffixlen$_InlineProcessor__placeholder_lengthINLINE_PLACEHOLDER_RE _InlineProcessor__placeholder_rer
   inlinePatterns	ancestors)r.   r
   s   &&r   __init__InlineProcessor.__init__P   sp    $($B$B!$(HH!$%D,E,E(F$F(+D,E,E(F%G! $ : : //$&r   c                    V ^8  d   QhRRRR/# )r	   typer$   r   ztuple[str, str]r   )r   s   "r   r   r9   Z   s      c o r   c                n    R\        V P                  4      ,          p\        P                  V,          pW23# )zGenerate a placeholder z%04d)r@   stashed_nodesr   INLINE_PLACEHOLDER)r.   rI   idhashs   &&  r   __makePlaceholder!InlineProcessor.__makePlaceholderZ   s.    c$,,--&&+xr   c               $    V ^8  d   QhRRRRRR/# )r	   datar$   indexintr   ztuple[str | None, int]r   )r   s   "r   r   r9   `   s"     # #c ## #:P #r   c                    V P                   P                  W4      pV'       d"   VP                  ^4      VP                  4       3# RV^,           3# )z
Extract id from data string, start from index.

Arguments:
    data: String.
    index: Index, from which we start search.

Returns:
    Placeholder id and string index, after the found placeholder.

N)rC   searchgroupend)r.   rR   rS   ms   &&& r   __findPlaceholder!InlineProcessor.__findPlaceholder`   sD     !!((5771:quuw&&?"r   c               $    V ^8  d   QhRRRRRR/# )r	   nodezetree.Element | strrI   r$   r   r   )r   s   "r   r   r9   r   s"       3 3 3 r   c                H    V P                  V4      w  r4WP                  V&   V# )zAdd node to stash. )!_InlineProcessor__makePlaceholderrK   )r.   r]   rI   placeholderrM   s   &&&  r   __stashNodeInlineProcessor.__stashNoder   s(    006!%2r   c               $    V ^8  d   QhRRRRRR/# )r	   rR   r$   patternIndexrT   r   r   )r   s   "r   r   r9   x   s!      3 c # r   c                    \        V\        P                  4      '       gZ   ^ p\        V P                  4      pW$8  d=   V P                  V P                  V,          WV4      w  rpV'       d   K7  V^,          pKB  V# )z
Process string with inline patterns and replace it with placeholders.

Arguments:
    data: A line of Markdown text.
    patternIndex: The index of the `inlinePattern` to start with.

Returns:
    String with placeholders.

)r"   r   r#   r@   rD   _InlineProcessor__applyPattern)r.   rR   rd   
startIndexcountmatcheds   &&&   r   __handleInlineInlineProcessor.__handleInlinex   so     $ 1 122J++,E&,0,?,?''5t:-)z w A%Lr   c               (    V ^8  d   QhRRRRRRRR/# )r	   r]   r*   subnodeisTextr    r   Noner   )r   s   "r   r   r9      s*     * * * *X\ *hl *r   c                L   V'       d   VP                   pRVn         MVP                  pRVn        V P                  WBV4      pV'       g(   WJd#   \        V4      P	                  V4      ^,           pM^ pVP                  4        V F  pVP                  Wg^ ,          4       K  	  R# )z
Process placeholders in `Element.text` or `Element.tail`
of Elements popped from `self.stashed_nodes`.

Arguments:
    node: Parent node.
    subnode: Processing node.
    isText: Boolean variable, True - it's text, False - it's a tail.

N)texttail%_InlineProcessor__processPlaceholderslistrS   reverseinsert)r.   r]   rm   rn   rq   childResultposnewChilds   &&&&    r   __processElementText$InlineProcessor.__processElementText   s     <<DGL<<DGL00G$-t*""7+a/CC#HKKa[) $r   c               (    V ^8  d   QhRRRRRRRR/# )	r	   rR   
str | Noneparentr*   rn   r    r   z%list[tuple[etree.Element, list[str]]]r   )r   s   "r   r   r9      s8     O OO O 	O
 
/Or   c                  aaa R VVV3R llp. o^ pV'       Ed   VP                  V P                  V4      pVR8w  Edo   V P                  W4      w  rxWpP                  9   Ed    V P                  P	                  V4      p	V^ 8  d   WV p
V! V
4       \        V	\        4      '       g   V	.\        V	4      ,            F  pVP                  '       d3   VP                  P                  4       '       d   V P                  WR4       VP                  '       g   K[  VP                  P                  4       '       g   K}  V P                  W4       K  	  MV! V	4       TpEKH  TpSP                  WP                  R,          34       EKp  V\        V P                  4      ,           pV! WV 4       TpEK  WR p
\        V\        P                   4      '       d   \        P                   ! V
4      p
V! V
4       RpEK  S# )ad  
Process string with placeholders and generate `ElementTree` tree.

Arguments:
    data: String with placeholders instead of `ElementTree` elements.
    parent: Element, which contains processing inline data.
    isText: Boolean variable, True - it's text, False - it's a tail.

Returns:
    List with `ElementTree` elements with applied inline patterns.

c                    V ^8  d   QhRRRR/# )r	   rq   r}   r   ro   r   )r   s   "r   r   ;InlineProcessor.__processPlaceholders.<locals>.__annotate__   s     	+ 	+: 	+$ 	+r   c                  < V '       d   S'       da   SR,          ^ ,          P                   '       d*   SR,          ^ ,          ;P                   V ,          un         R# V SR,          ^ ,          n         R# S'       g7   SP                   '       d   S;P                   V ,          un         R# V Sn         R# SP                  '       d   S;P                  V ,          un        R# V Sn        R# R# )   N)rr   rq   )rq   rn   r~   results   &r   linkText7InlineProcessor.__processPlaceholders.<locals>.linkText   s    bz!})))r
1**d2*-1r
1*{{{t+&*{{{t+&* r   FNNNN r   )findr=   !_InlineProcessor__findPlaceholderrK   getr"   r$   rt   rr   strip$_InlineProcessor__processElementTextrq   appendrE   r@   r   r#   )r.   rR   r~   rn   r   strartIndexrS   rM   
phEndIndexr]   rq   childrX   r   s   &&ff         @r   __processPlaceholders%InlineProcessor.__processPlaceholders   s   $	+ 	+" dIId77EE{!%!7!7!D+++--11"5Dqy#6 %dC00&*Vd4j%8%8E$zzz#(::#3#3#5#5$($=$=(,U%&  %zzz#(::#3#3#5#5$($=$=e$K &9 !&0 ",KMM4):";<  #d&?&?"@@CTc23"%KL)dD$5$566,,T2Dr   c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r	   patternzinlinepatterns.PatternrR   r$   rd   rT   rg   r   ztuple[str, bool, int]r   )r   s   "r   r   r9      sJ     NO NO'NO NO 	NO
 NO 
NOr   c                   \        V\        P                  4      pVP                   F)  pVP	                  4       V P
                  9   g   K$  VR^ 3u # 	  V'       da   RpVP                  4       P                  W$4       F:  pVP                  Wr4      w  rp
V	e   V
f   WGP                  ^ 4      ,          pRpK:   M)	  M&VP                  4       P                  W$R 4      pVRV pV'       g   VR^ 3# V'       g4   VP                  V4      pVP                  ^ 4      p	VP                  ^ 4      p
Xf   VRX
3# \        V\        4      '       Eg   \        VP                  \        P                  4      '       g   V.\!        V4      ,            F  p\#        V4      '       d   K  VP                  '       dv   V P
                  P%                  VP&                  P	                  4       4       V P)                  VP                  V^,           4      Vn        V P
                  P+                  4        VP,                  '       g   K  V P)                  VP,                  V4      Vn        K  	  V P/                  WP1                  4       4      pV'       d   RP3                  VRX	 WX
R 4      R^ 3# RP3                  XVP5                  ^4      WP7                  4       R,          4      R^ 3# )ak  
Check if the line fits the pattern, create the necessary
elements, add it to `stashed_nodes`.

Arguments:
    data: The text to be processed.
    pattern: The pattern to be checked.
    patternIndex: Index of current pattern.
    startIndex: String index, from which we start searching.

Returns:
    String with placeholders instead of `ElementTree` elements.

FNTz{}{}{}z{}{}{}{}r   )r"   r   r   ANCESTOR_EXCLUDESlowerrE   getCompiledRegExpfinditerhandleMatchrX   matchstartr$   rq   r   r#   rt   r%   r   tag_InlineProcessor__handleInlinepoprr   _InlineProcessor__stashNoderI   r   rW   groups)r.   r   rR   rd   rg   	new_styleexcluder   r]   r   rX   leftDatar   r`   s   &&&&&         r   __applyPatternInlineProcessor.__applyPattern   sh   * w(F(FG	00G}}$..0UA~% 1 E !224==dO#*#6#6u#C S=CK))A,.J E P --/55d;6GHEKZ(H>!&&u-DKKNE))A,C<s?"$$$dii):):;;"Vd4j00E#D>> ::: NN11%))//2CD)-)<)< %

L1,<*EJ !NN..0 :::)-)<)< %

L*EJ 1 &&t\\^<??4<#.ST
<=A1E E $$X%*[[^%0,,.2DFGKQO Or   c               $    V ^8  d   QhRRRRRR/# )r	   r~   r+   parentsz	list[str]r   ro   r   )r   s   "r   r   r9   M  s#     " "(< "y "UY "r   c                    . pVeK   Ve*   VP                  VP                  P                  4       4       V P                  P	                  V4      pKN  VP                  4        VP                  V4       R# )zBuild the ancestor list.N)r   r   r   
parent_mapr   ru   extend)r.   r~   r   rE   s   &&& r   __build_ancestors!InlineProcessor.__build_ancestorsM  sZ    	 !  !1!1!34__((0Fy!r   Nc               $    V ^8  d   QhRRRRRR/# )r	   treer*   rE   zlist[str] | Noner   r   )r   s   "r   r   r9   W  s'     E E E2B Em Er   c                   / V n         Vf   . MVR,          pVP                  4        UUu/ uF  qD F  qUVbK  	  K  	  uppV n        W3.pV'       Ed   VP                  ^ 4      w  rxWn        V P                  WpP                  4       . p	V EF%  p
V
P                  '       d   \        V
P                  \        P                  4      '       g   V P                  P                  V
P                  P                  4       4       V
P                  pRV
n        V P                  V P                  V4      V
4      pV F  pWP                  V^ ,          &   K  	  Wl,          pV	P                  W34       V P                  P                  4        V
P                  '       d   V P                  V
P                  4      p\         P"                  ! R4      pRV
n        V P                  WR4      pVP                  '       d   VP                  V
n        \%        V4      P'                  V
4      ^,           pVP)                  4        V F1  pWpP                  V^ ,          &   VP+                  VV^ ,          4       K3  	  \-        V
4      '       g   EK  WpP                  V
&   VP                  WP                  R,          34       EK(  	  V	 F6  w  pp\/        V4       F!  w  ppV^ ,          pVP+                  VV4       K#  	  K8  	  EK  V# u uppi )a_  Apply inline patterns to a parsed Markdown tree.

Iterate over `Element`, find elements with inline tag, apply inline
patterns and append newly created Elements to tree.  To avoid further
processing of string with inline patterns, instead of normal string,
use subclass [`AtomicString`][markdown.util.AtomicString]:

    node.text = markdown.util.AtomicString("This will not be processed.")

Arguments:
    tree: `Element` object, representing Markdown tree.
    ancestors: List of parent tag names that precede the tree node (if needed).

Returns:
    An element tree object with applied inline patterns.

Nr   dF)rK   iterr   r   rE   !_InlineProcessor__build_ancestorsrq   r"   r   r#   r   r   r   rs   r   rr   etreeElementrt   rS   ru   rv   r@   	enumerate)r.   r   rE   tree_parentspcstackcurrElementr   insertQueuer   rq   lstitemrr   dumby
tailResultrx   ry   elementiobjs   &&&                   r   r/   InlineProcessor.runW  sc   $ >@ '.rIaL)-@Aaa4a1@%&e#(99Q< K$N"";?K$:::jJJ 1 1' ' NN))%))//*;< ::D!%EJ44++D15C !$38Q0 !$LE&&|4NN&&(:::..uzz:D!MM#.E!%EJ!%!;!;D!OJzzz%*ZZ
{+11%81<C&&($.7B4#**3< %/ u::-8OOE*LL%):!;<; %> !,'nFAs"1vHNN1h/ - !, [ As   K6)	__placeholder_length__placeholder_prefix__placeholder_re__placeholder_suffixrE   rD   r
   r   rK   )    )TN)r1   r2   r3   r4   r5   rF   r_   r   r   r   r   rs   rf   r   r/   r6   r   r   r   r   r   K   sE    '#$.*:ObNO`"E Er   r   c                  2    ] tR tRtRtR R ltR R ltRtR# )	r   i  z&Add line breaks to the html document. c                    V ^8  d   QhRRRR/# )r	   elemr*   r   ro   r   )r   s   "r   r   "PrettifyTreeprocessor.__annotate__  s      = T r   c                z   RpV P                   P                  VP                  4      '       d   VP                  R9  d   VP                  '       d!   VP                  P	                  4       '       gJ   \        V4      '       d9   V P                   P                  V^ ,          P                  4      '       d   W!n        V FA  pV P                   P                  VP                  4      '       g   K0  V P                  V4       KC  	  VP                  '       d!   VP                  P	                  4       '       g	   W!n        R# R# )z7Recursively add line breaks to `ElementTree` children. 
N)codepre)r
   is_block_levelr   rq   r   r@   _prettifyETreerr   )r.   r   r   es   &&  r   r   $PrettifyTreeprocessor._prettifyETree  s     77!!$((++0OIIITYY__%6%6D		dgg&<&<T!W[[&I&I	77))!%%00''*  yyy		 1 1I !2r   c                    V ^8  d   QhRRRR/# r	   r)   r*   r   ro   r   )r   s   "r   r   r     s     M M M$ Mr   c                \   V P                  V4       VP                  R4      pV FV  pVP                  '       d!   VP                  P                  4       '       g
   RVn        K>  RVP                  ,          Vn        KX  	  VP                  R4      pV F  p\	        V4      '       g   K  V^ ,          P
                  R8X  g   K0  V^ ,          p\	        V4      '       d   KL  VP                  f   K\  \        P                  ! VP                  P                  4       R,           4      Vn        K  	  R# )z6Add line breaks to `Element` object and its children. brr   z
%sr   r   N)
r   r   rr   r   r@   r   rq   r   r#   rstrip)r.   r)   brsr   presr   r   s   &&     r   r/   PrettifyTreeprocessor.run  s     	D! iioB777"''--// 277*	  yyC3xxCFJJ&01v4yyTYY%: $ 1 1$))2B2B2Dt2K LDI r   r   N)r1   r2   r3   r4   r5   r   r/   r6   r   r   r   r   r     s    1M Mr   r   c                      ] tR tRtRt]P                  ! RP                  ]P                  ]P                  4      4      tR R ltR R ltR R	 ltR
tR# )r   i  zRestore escaped chars z	{}(\d+){}c                    V ^8  d   QhRRRR/# )r	   rY   zre.Match[str]r   r$   r   )r   s   "r   r   "UnescapeTreeprocessor.__annotate__  s     $ $= $S $r   c                	H    \        \        VP                  ^4      4      4      # )r   )chrrT   rW   )r.   rY   s   &&r   	_unescapeUnescapeTreeprocessor._unescape  s    3qwwqz?##r   c                    V ^8  d   QhRRRR/# )r	   rq   r$   r   r   )r   s   "r   r   r     s     1 1S 1S 1r   c                	N    V P                   P                  V P                  V4      # r   )REsubr   )r.   rq   s   &&r   r   UnescapeTreeprocessor.unescape  s    ww{{4>>400r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r     s     4 4 4$ 4r   c                   VP                  4        F  pVP                  '       d2   VP                  R8X  g!   V P                  VP                  4      Vn        VP                  '       d!   V P                  VP                  4      Vn        VP                  4        F%  w  r4VP                  W0P                  V4      4       K'  	  K  	  R# )z.Loop over all elements and unescape all text. r   N)r   rq   r   r   rr   itemsset)r.   r)   r   keyvalues   &&   r   r/   UnescapeTreeprocessor.run  s~    IIKDyyyV!3 MM$))4	yyy MM$))4	"jjl
mmE23 +  r   r   N)r1   r2   r3   r4   r5   recompiler   r   STXr>   r   r   r   r/   r6   r   r   r   r   r     s<    !	L''$((;	<B$14 4r   r   )r5   
__future__r   r   xml.etree.ElementTreer   ElementTreetypingr   r   r   r   r   markdownr   r   r%   	Processorr'   r   r   r   r   r   r   <module>r      sk   ( # 	 % % %  !DNN (Qm Qh
$MM $MN4M 4r   