+
    f0iG                       R t ^ RIHt ^RIHt ^RIHt ^RIHtH	t	H
t
HtHt ^RIHt ^RIHt ^ RIt^ RIt^ RIt^ RIHt ^ RIHu Ht ^ R	IHtHtHtHt ]'       d   ^ R
IHt R*R R lltR R lt ]PB                  ! R4      t"R R lt#]
! R4      R R l4       t$]
! R4      R+R R ll4       t%R R lt&R R lt'R R lt(R R lt)R  R! lt*R" R# lt+R$ t, ! R% R&]4      t- ! R' R(]4      t.R) t/R# ),z
Add table of contents support to Python-Markdown.

See the [documentation](https://Python-Markdown.github.io/extensions/toc)
for details.
)annotations)	Extension)Treeprocessor)parseBoolValueAMP_SUBSTITUTE
deprecatedHTML_PLACEHOLDER_REAtomicString)UnescapeTreeprocessor)RE_AMPN)deepcopy)TYPE_CHECKINGAnyIterator
MutableSet)Markdownc               (    V ^8  d   QhRRRRRRRR/# )   valuestr	separatorunicodeboolreturn )formats   "]/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/markdown/extensions/toc.py__annotate__r   &   s.     B B3 B3 B B# B    c                6   V'       g9   \         P                  ! RV 4      p V P                  RR4      P                  R4      p \        P
                  ! RRV 4      P                  4       P                  4       p \        P
                  ! RP                  V4      W4      # )z+Slugify a string, to make it URL friendly. NFKDasciiignorez[^\w\s-] z[{}\s]+)	unicodedata	normalizeencodedecoderesubstriplowerr   )r   r   r   s   &&&r   slugifyr,   &   sr    %%fe4Wh/66w?FF;E*00288:E66*##I.	AAr   c               $    V ^8  d   QhRRRRRR/# )r   r   r   r   r   r   )r   s   "r   r   r   0   s!     3 33 33 33 3r   c                    \        WRR7      # )zOSlugify a string, to make it URL friendly while preserving Unicode characters. T)r   )r,   )r   r   s   &&r   slugify_unicoder/   0   s    5T22r   z^(.*)_([0-9]+)$c               $    V ^8  d   QhRRRRRR/# )r   idr   idszMutableSet[str]r   r   )r   s   "r   r   r   8   s!     	 	s 	 	S 	r   c                   W9   g	   V '       gf   \         P                  V 4      pV'       d<   RVP                  ^4      \        VP                  ^4      4      ^,           3,          p Kf  RV ^3,          p Ks  VP	                  V 4       V # )z?Ensure id is unique in set of ids. Append '_1', '_2'... if not z%s_%d)
IDCOUNT_REmatchgroupintadd)r1   r2   ms   && r   uniquer:   8   sb    
)2R AGGAJAGGAJ(9::BB7"BGGBKIr   z0Use `render_inner_html` and `striptags` instead.c                    V ^8  d   QhRRRR/# )r   eletree.Elementr   r   r   )r   s   "r   r   r   E   s     	! 	! 	!3 	!r   c                   . pV P                  4        FQ  p\        V\        4      '       d(   VP                  \        P
                  ! V4      4       K@  VP                  V4       KS  	  RP                  V4      P                  4       # )zGet title name.r#   )itertext
isinstancer	   appendhtmlunescapejoinr*   )r<   textcs   &  r   get_namerG   D   s_     D[[]a&&KKa()KKN	 
 774=  r   zIUse `run_postprocessors`, `render_inner_html` and/or `striptags` instead.c               (    V ^8  d   QhRRRRRRRR/# )r   rE   r   mdr   strip_entitiesr   r   r   )r   s   "r   r   r   R   s(     4 43 4H 4d 4c 4r   c                F   aa R VV3R llp\         P                  ! W04      # )zMExtract raw HTML from stash, reduce to plain text and swap with placeholder. c                    V ^8  d   QhRRRR/# )r   r9   zre.Match[str]r   r   r   )r   s   "r   r   &stashedHTML2text.<locals>.__annotate__T   s     
 
] 
s 
r   c                4  <  SP                   P                  \        V P                  ^4      4      ,          p\        P                  ! RRT4      pS'       d   \        P                  ! RRT4      pT#   \        \
        3 d    T P                  ^ 4      u # i ; i)z%Substitute raw html with plain text. z	(<[^>]+>)r#   z(&[\#a-zA-Z0-9]+;))	htmlStashrawHtmlBlocksr7   r6   
IndexError	TypeErrorr(   r)   )r9   rawresrI   rJ   s   &  r   	_html_sub#stashedHTML2text.<locals>._html_subT   s{    	,,,,S_=C ff\2s+&&.C8C
 I& 	771:	s   5A2 2"BB)r   r)   )rE   rI   rJ   rU   s   &ff r   stashedHTML2textrW   Q   s     
 
 ""933r   c                    V ^8  d   QhRRRR/# r   rE   r   r   r   )r   s   "r   r   r   c   s      3 3 r   c                8    \        4       pVP                  V 4      # )z*Unescape Markdown backslash escaped text. )r
   rC   )rE   rF   s   & r   rC   rC   c   s    A::dr   c                    V ^8  d   QhRRRR/# rY   r   )r   s   "r   r   r   i   s      S S r   c                X   V P                  R4      ;pR8w  d.   V P                  RV4      ;pR8w  d   V RV  W^,           R  2p KE  V P                  R4      ;pR8w  d.   V P                  RV4      ;pR8w  d   V RV  W^,           R  2p KE  RP                  V P                  4       4      p V # )zKStrip HTML tags and return plain text. Note: HTML entities are unaffected. z<!--z-->N<> )findrD   split)rE   startends   &  r   
strip_tagsre   i   s     IIf%%5"
,5%9P2P#UW1Wv,1WX/0IIcN"5r
)diiU6K/KsPR.Rv,1WX/0 88DJJL!DKr   c                    V ^8  d   QhRRRR/# rY   r   )r   s   "r   r   r   w   s     	 	s 	s 	r   c                    RV 9   d   \         P                  ! RV 4      p RV 9   d   V P                  RR4      p RV 9   d   V P                  RR4      p V # )zEscape character data. &z&amp;r]   z&lt;r^   z&gt;)r   r)   replace)rE   s   &r   escape_cdatarj   w   sL    
d{zz'4(
d{||C(
d{||C(Kr   c               $    V ^8  d   QhRRRRRR/# )r   rE   r   rI   r   r   r   )r   s   "r   r   r      s!      S h 3 r   c                j    VP                    F  pVP                  V 4      p K  	  V P                  4       # )z3Run postprocessors from Markdown instance on text. )postprocessorsrunr*   )rE   rI   pps   && r   run_postprocessorsrp      s+    vvd|  ::<r   c               $    V ^8  d   QhRRRRRR/# )r   r<   r=   rI   r   r   r   r   )r   s   "r   r   r      s!     
( 
(- 
(X 
(# 
(r   c                    \        VP                  V 4      4      pVP                  R4      ^,           pVP                  R4      pW#V P	                  4       p\        W!4      # )z;Fully render inner html of an `etree` element as a string. r^   r]   )rC   
serializerindexrindexr*   rp   )r<   rI   rE   rc   rd   s   &&   r   render_inner_htmlrv      sV     BMM"%&D JJsOaE
++c
Cc?  "Dd''r   c                    V ^8  d   QhRRRR/# )r   rootr=   r   r   )r   s   "r   r   r      s       - r   c                $   \        V P                  R4      R4      f   V # \        V 4      p V P                  R4       F  pRp\	        V4       F  pVP
                  R8X  dU   VP                  RR4      P                  R4      '       d.   VP                  ;'       g    R V 2pVP                  V4       Kh  V'       g   Kr  VP                  ;'       g    R V 2Vn        RpK  	  V'       g   K  VP                  ;'       g    R V 2Vn
        K  	  V # )zKRemove footnote references from a copy of the element, if any are present. supNz	.//sup/..r#   r1   fnref)nextiterr   findallreversedtagget
startswithtailremoverE   )rx   parent
carry_textchilds   &   r   remove_fnrefsr      s     DIIed#+D>D,,{+
f%EyyE!eiib&9&D&DW&M&M %

 0 0b1*>
e$ %

 0 0b1*>

 & :#[[..B/
|<FK , Kr   c                   . p\        V 4      '       Ed@   V P                  ^ 4      p. VR&   VR,          .pVP                  V4       . pV '       Ed   V P                  ^ 4      pVR,          p. VR&   WcR,          8  db   VP                  4        ^ p\        V4       F  pWhR,          8:  d   V^,          pK   M	  V'       d   VRV)  pVRV)  pVP                  V4       WcR,          8X  d+   V'       d   VR,          R,          MTP                  V4       M:VR,          P                  V4       VP                  V4       VP                  V4       TpEK  V# )a6  Given an unsorted list with errors and skips, return a nested one.

    [{'level': 1}, {'level': 2}]
    =>
    [{'level': 1, 'children': [{'level': 2, 'children': []}]}]

A wrong list is also converted:

    [{'level': 2}, {'level': 1}]
    =>
    [{'level': 2, 'children': []}, {'level': 1, 'children': []}]
childrenlevelNr`   )lenpoprA   r   )	toc_listordered_listlastlevelsparentstcurrent_levelto_popps	   &        r   nest_toc_tokensr      s:    L
8}}||AZw-D! hQAgJMAjM bz)

 !'*A$'
2!	 +
 #HfW-F%hw/G m, r
*,3Z("FF1I
 Z ''*t$m,Dr   c                     a  ] tR t^tRtR V 3R lltR R ltR R ltR R	 ltR
 R lt	R R lt
R R ltR R ltRtV ;t# )TocTreeprocessorz%Step through document and build TOC. c                    V ^8  d   QhRRRR/# )r   rI   r   configzdict[str, Any]r   )r   s   "r   r   TocTreeprocessor.__annotate__   s     7 78 7^ 7r   c                	v  < \         SV `  V4       VR ,          V n        VR,          V n        \	        VR,          4      ^,
          V n        VR,          V n        VR,          V n        VR,          V n        VR,          V n	        \        VR,          4      V n        VR,          V n        \        VR	,          R
4      V n        V P                  f   VR	,          V n        VR,          V n        VR,          V n        \        VR,          R
4      V n        \"        P$                  ! R4      V n        \)        VR,          \*        4      '       dO   RVR,          9   dA   VR,          P-                  R4       Uu. uF  p\	        V4      NK  	  upw  V n        V n        R# ^V n        \	        VR,          4      V n        R# u upi )markertitle	baselevelr,   r   	toc_classtitle_class
anchorlinkanchorlink_class	permalinkFNpermalink_classpermalink_titlepermalink_leadingz[Hh][123456]	toc_depth-)super__init__r   r   r7   
base_levelr,   sepr   r   r   use_anchorsr   use_permalinksr   r   r   r(   compile
header_rgxr@   r   rb   toc_top
toc_bottom)selfrI   r   x	__class__s   &&& r   r   TocTreeprocessor.__init__   sm   !(+ /
f[12Q6i(+&, &} 5!/|0D!E%+,>%?,VK-@%H&"("5D$*+<$=$*+<$=.<VDW=XZ_.`**^4f[)3//C6+;N4N=CK=P=V=VWZ=[,\=[SV=[,\)DL$/DL!&"56DO -]s   0F6c                    V ^8  d   QhRRRR/# )r   noder=   r   z-Iterator[tuple[etree.Element, etree.Element]]r   )r   s   "r   r   r     s     	2 	2} 	21^ 	2r   c              #     "   V Fa  pV P                   P                  VP                  4      '       d   K0  VP                  R9  g   KC  W3x  V P                  V4       Rj  xL
  Kc  	  R#  L
5i)z>Iterator wrapper to get allowed parent and child all at once. N)precode)r   r5   r   
iterparent)r   r   r   s   && r   r   TocTreeprocessor.iterparent  sT      E??((33		8Xk!??5111  2s   .A.A.A.!A,"A.c               $    V ^8  d   QhRRRRRR/# )r   rx   r=   elemr   Noner   )r   s   "r   r   r     s!      =  $ r   c                   V P                  V4       F  w  r4RP                  VP                  4       4      P                  4       pV'       g   K<  VP                  '       g   KP  VP                  P                  4       V P
                  8X  g   K{  \        V4      ^ 8X  g   K  \        \        V4      4       F  pW6,          V8X  g   K  W#V&    K  	  K  	  R# )zReplace marker with elem. r#   N)r   rD   r?   r*   rE   r   r   range)r   rx   r   r   rF   rE   is   &&&    r   replace_markerTocTreeprocessor.replace_marker  s    ood+FQ771::<(..0D vvv!&&,,.DKK7CFaKs1vAtqy#! ' ,r   c                    V ^8  d   QhRRRR/# )r   r   r=   r   r   r   )r   s   "r   r   r   +  s     ! !m ! !r   c                    \        VP                  R,          4      V P                  ,           pV^8  d   ^pRV,          Vn        R# )z-Adjust header level according to base level. zh%dNr`   )r7   r   r   )r   r   r   s   && r   	set_levelTocTreeprocessor.set_level+  s4    DHHRL!DOO319E5=r   c               $    V ^8  d   QhRRRRRR/# r   rF   r=   elem_idr   r   r   r   )r   s   "r   r   r   2  s!     
 
M 
C 
D 
r   c                	l   \         P                  ! R 4      pVP                  Vn        RV,           VP                  R&   V P                  VP                  R&   RVn        V F  pVP                  V4       K  	  \        V4      '       d   VP                  V^ ,          4       K+  VP                  V4       R# )a#hrefclassr#   N)etreeElementrE   attribr   rA   r   r   )r   rF   r   anchorr   s   &&&  r   
add_anchorTocTreeprocessor.add_anchor2  s    s#ff #gf!%!6!6gDMM$ !ffHHQqTN	r   c               $    V ^8  d   QhRRRRRR/# r   r   )r   s   "r   r   r   >  s!        }  s  t  r   c                	   \         P                  ! R 4      pV P                  RJ d   R\        ,          MV P                  Vn        RV,           VP
                  R&   V P                  VP
                  R&   V P                  '       d   V P                  VP
                  R&   V P                  '       d-   VP                  Vn	        RVn        VP                  ^ V4       R# VP                  V4       R# )	r   Tz%spara;r   r   r   r   r#   N)r   r   r   r   rE   r   r   r   r   r   insertrA   )r   rF   r   r   s   &&& r   add_permalinkTocTreeprocessor.add_permalink>  s    MM#&	!00D8 $n4#22 	 $'=	 $($8$8	!(,(<(<IW%!!!VVINAFHHQ	"HHYr   c                    V ^8  d   QhRRRR/# )r   r   listr   r=   r   )r   s   "r   r   r   N  s      d } r   c                  a \         P                  ! R4      pV P                  VP                  R&   V P                  '       dT   \         P
                  ! VR4      pV P                  '       d   V P                  VP                  R&   V P                  Vn        R V3R lloS! W4       RV P                  P                  9   d-   V P                  P                  R,          P                  V4       V# )z&Return a string div given a toc list. divr   spanc               $    V ^8  d   QhRRRRRR/# )r   r   r   r   r=   r   r   )r   s   "r   r   4TocTreeprocessor.build_toc_div.<locals>.__annotate__Z  s!     
	 
	T 
	= 
	] 
	r   c                `  < \         P                  ! VR 4      pV  F  p\         P                  ! VR4      p\         P                  ! VR4      pVP                  RR4      Vn        RVP                  RR4      ,           VP                  R&   VR,          '       g   K  S! VR,          V4       K  	  V# )	ullir   namer#   r   r1   r   r   )r   
SubElementr   rE   r   )r   r   r   itemr   linkbuild_etree_uls   &&    r   r   6TocTreeprocessor.build_toc_div.<locals>.build_etree_ulZ  s    !!&$/B %%b$/''C0 HHVR0	&)DHHT2,>&>F#
##"4
#3R8 ! Ir   prettify)r   r   r   r   r   r   r   rE   rI   treeprocessorsrn   )r   r   r   headerr   s   &&  @r   build_toc_divTocTreeprocessor.build_toc_divN  s    mmE""nn

7 :::%%c62F)-)9)9g&**FK
	 
	 	x%///GG"":.2237
r   c                    V ^8  d   QhRRRR/# )r   docr=   r   r   r   )r   s   "r   r   r   m  s     2 2} 2 2r   c                	   \        4       pVP                  4        F8  pR VP                  9   g   K  VP                  VP                  R ,          4       K:  	  . pVP                  4        EFY  p\	        VP
                  \        4      '       g   K&  V P                  P                  VP
                  4      '       g   KS  V P                  V4       \        \        V4      V P                  4      p\        V4      pR VP                  9  dH   \        V P                  \         P"                  ! V4      V P$                  4      V4      VP                  R &   RpRVP                  9   dR   \'        \#        VP                  R,          4      V P                  4      p\)        \        V4      4      pVP                  R \+        VP
                  R,          4      V P,                  8  d{   \+        VP
                  R,          4      V P.                  8:  dP   VP1                  R\+        VP
                  R,          4      R \#        VP                  R ,          4      RVRVRV/4       V P2                  '       d#   V P5                  W3P                  R ,          4       V P6                  R9  g   EK7  V P9                  W3P                  R ,          4       EK\  	  \;        V4      pV P=                  V4      pV P>                  '       d   V PA                  W4       V P                  PC                  V4      p	V P                  PD                   F  p
V
PG                  V	4      p	K  	  W@P                  n$        WP                  n%        R# )	r1   r#   zdata-toc-labelr   r   rB   Nr`   )FN)&setr}   r   r8   r@   r   r   r   r5   r   rv   r   rI   re   r:   r,   rB   rC   r   rp   rj   r7   r   r   rA   r   r   r   r   r   r   r   r   rs   rm   rn   
toc_tokenstoc)r   r   used_idsr<   r   	innerhtmlr   data_toc_labelr   r   ro   s   &&         r   rn   TocTreeprocessor.runm  sf   5((*Bryy RYYt_-  
((*B"&&#&&4??+@+@+H+Hr"-mB.?I	!), ryy(&,T\\$--:Mtxx-XZb&cBIIdO!##ryy0%7K[A\8]_c_f_f%gN'
>(BCD		"23rvvbz?dll2s266":$//7Y%%RVVBZhryy7	(.'  ###OOB		$8&&m;&&r99T?;= @ %Z0
  ,;;;) gg  %''((B&&+C )'r   )r   r   r   r   r   r   r   r   r,   r   r   r   r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   r   r   rn   __static_attributes____classcell__r   s   @r   r   r      s8    07 72	2*!
  >2 2r   r   c                  >   a  ] tR tRt]tV 3R ltR tR R ltRt	V ;t
# )TocExtensioni  c                	   < R RR.RRR.RRR.R	R
R.RRR.RRR.R^ R.RRR.RRR.RRR.RRR.R\         R .R!R"R#.R$^R%./V n         \        SV `  ! R'/ VB  R&# )(r   z[TOC]zeText to find and replace with Table of Contents. Set to an empty string to disable. Default: `[TOC]`.r   r#   z;Title to insert into TOC `<div>`. Default: an empty string.r   toctitlez2CSS class used for the title. Default: `toctitle`.r   r   z4CSS class(es) used for the link. Default: `toclink`.r   Fz7True if header should be a self link. Default: `False`.r   toclinkz5CSS class(es) used for the link. Defaults: `toclink`.r   zPTrue or link text if a Sphinx-style permalink should be added. Default: `False`.r   
headerlinkz7CSS class(es) used for the link. Default: `headerlink`.r   zPermanent linkz<Title attribute of the permalink. Default: `Permanent link`.r   z\True if permalinks should be placed at start of the header, rather than end. Default: False.r   1z%Base level for headers. Default: `1`.r,   zFFunction to generate anchors based on header text. Default: `slugify`.r   r   zWord separator. Default: `-`.r   a'  Define the range of section levels to include in the Table of Contents. A single integer (b) defines the bottom section level (<h1>..<hb>) only. A string consisting of two digits separated by a hyphen in between (`2-5`) defines the top (t) and the bottom (b) (<ht>..<hb>). Default: `6` (bottom).Nr   )r,   r   r   r   )r   kwargsr   s   &,r   r   TocExtension.__init__  s    $
 Q P M P R! e W   "`   n" #FGa #>?)O.
^ 	/"6"r   c                    VP                  V 4       Wn        V P                  4        V P                  WP	                  4       4      pVP
                  P                  VR^4       R# )z$Add TOC tree processor to Markdown. r   N)registerExtensionrI   resetTreeProcessorClass
getConfigsr   register)r   rI   tocexts   && r   extendMarkdownTocExtension.extendMarkdown  sM    
T"

((__->?
""65!4r   c                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r   TocExtension.__annotate__  s        t  r   c                	J    R V P                   n        . V P                   n        R# )r#   N)rI   r   r   )r   s   &r   r  TocExtension.reset  s    r   )r   rI   )r   r   r   r  r   r  r   r  r  r  r  r  s   @r   r  r    s    )2#h5   r   r  c                     \        R/ V B # )Nr   )r  )r  s   ,r   makeExtensionr    s    !&!!r   )F)T)0r  
__future__r   r#   r   r   r   utilr   r   r   r   r	   r
   serializersr   r(   rB   r$   copyr   xml.etree.ElementTreer   ElementTreetypingr   r   r   r   markdownr   r,   r/   r   r4   r:   rG   rW   rC   re   rj   rp   rv   r   r   r   r  r  r   r   r   <module>r&     s    #  * ` ` 2   	    % % ; ;!B3
 ZZ*+
	 >?	! @	! WX4 Y4"	
(.>Bp} pfB 9 B J"r   