
    iKj`                        d dl Z d dlmZmZmZmZmZmZ ddlm	Z	 ddl
mZ erddlmZ ddlmZmZ ddlmZ dd	lmZ d
gZ e j*                  d      ZdZdez   dz   Zdez   dz   Zdddee   dddefdZdddee   de	defdZdddedede	deeef   f
dZddd eeeeeef      f   de	deeeeeef      f   fd!Zd"d#dededefd$Z d"d#d%edefd&Z!d"d#d%edededef
d'Z"d)d(Z#y)*    N)TYPE_CHECKINGAnyDictListMatchUnion   )
BlockState)unikey)BlockParser)BaseRendererInlineState)InlineParser)Markdown	footnotesz\n{2,}z(?:[^\\\[\]\s]|\\.){1,500}z/^(?P<footnote_lead> {0,4})\[\^(?P<footnote_key>zW)]:[ \t\n](?P<footnote_text>[^\n]*(?:\n+|$)(?:(?P=footnote_lead) {1,4}(?! )[^\n]*\n+)*)z\[\^(?P<footnote_key>z)\]inliner   mstater   returnc                    t        |j                  d            }|j                  j                  d      }|r||v r||j                  j                  d      }|sg }||vr |j	                  |       ||j                  d<   |j                  d|d|j                  |      dz   id       |j                         S |j                  d|j                  d	      d
       |j                         S )Nfootnote_keyref_footnotesr   footnote_refindex   )typerawattrstextr   )r   r   )r   groupenvgetappendappend_tokenr   end)r   r   r   keyrefnotess         j/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/mistune/plugins/footnotes.pyparse_inline_footnoter*      s    
(
)C
))--
(C
scz		k*EeLL%*EIIk"N3'SXS^S^_bScfgSgIhij 557N 	F1771:>?557N    blockr   c                     |j                   j                  d      }|si }t        |j                  d            }||vr#|j                  d      ||<   ||j                   d<   |j	                         S )Nr   r   footnote_text)r!   r"   r   r    r%   )r,   r   r   r'   r&   s        r)   parse_ref_footnoter/   .   sa    
))--
(C
(
)C
#~77?+C%(		/"557Nr+   r&   r   c                 B   |j                   j                  d      }|st        d      ||   }|j                         }d }|dd  D ]  }|s n |rt	        |      t	        |j                               z
  }t        j                  dt        |      z   dz   t        j                        }	|	j                  d|      j                         }t               }
|
j                  |       | j                  |
       |
j                  }n|j                         }d|d	g}d
|||ddS )Nr   zMissing 'ref_footnotes'.r   z^ {z,})flags 	paragraph)r   r   footnote_item)r&   r   )r   childrenr   )r!   r"   
ValueError
splitlineslenlstriprecompilestrMsubstripr
   processparsetokens)r,   r&   r   r   r'   r   linessecond_linespacespatternfooter_stater5   s               r)   parse_footnote_itemrH   :   s   
))--
(C344s8DOOEKQRy ! [!C(:(:(<$==**Vc&k1E9F{{2t$**,!|T"L!&&zz|($78#CZ_D`aar+   mdr   resultc           
         |j                   j                  d      }|s|S t        |      D cg c]   \  }}t        | j                  ||dz   |      " }}}t        |      }d|dg|_        | j                  |      }||z   S c c}}w )Nr   r   )parent)r   r5   )r!   r"   	enumeraterH   r,   r
   rB   render_state)rI   rJ   r   r(   ikr5   outputs           r)   md_footnotes_hookrR   U   s     IIMM+&EKTUZK[\K[41a#BHHaQ>K[H\e$E(h?@EL__U#FF?	 ]s   %Brendererr   c                 J    t        |      }d|z   dz   }|dz   |z   dz   |z   dz   S )Nz$<sup class="footnote-ref" id="fnref-">z<a href="#fn-z
</a></sup>)r<   )rS   r&   r   rO   htmls        r)   render_footnote_refrW   c   s9    E
A1A5<D/!A%,q0<??r+   r   c                     d|z   dz   S )Nz!<section class="footnotes">
<ol>
z</ol>
</section>
 )rS   r   s     r)   render_footnotesrZ   i   s    047:OOOr+   c                     t        |      }d|z   dz   }|j                         }|j                  d      r|d d |z   dz   }n|dz   |z   }d|z   dz   |z   dz   S )	Nz<a href="#fnref-z" class="footnote">&#8617;</a>z</p>
z<li id="fn-rU   z</li>
)r<   rstripendswith)rS   r   r&   r   rO   backs         r)   render_footnote_itemra   m   so    E
A!$DDD;;=D}}VCRy4&(d{T!1t#d*Y66r+   c                    | j                   j                  dt        t        d       | j                  j                  dt
        t        d       | j                  j                  t               | j                  r{| j                  j                  dk(  ra| j                  j                  dt               | j                  j                  dt               | j                  j                  d	t               y
y
y
)a  A mistune plugin to support footnotes, spec defined at
    https://michelf.ca/projects/php-markdown/extra/#footnotes

    Here is an example:

    .. code-block:: text

        That's some text with a footnote.[^1]

        [^1]: And that's the footnote.

    It will be converted into HTML:

    .. code-block:: html

        <p>That's some text with a footnote.<sup class="footnote-ref" id="fnref-1"><a href="#fn-1">1</a></sup></p>
        <section class="footnotes">
        <ol>
        <li id="fn-1"><p>And that's the footnote.<a href="#fnref-1" class="footnote">&#8617;</a></p></li>
        </ol>
        </section>

    :param md: Markdown instance
    footnotelink)beforeref_footnoteref_linkrV   r   r4   r   N)r   registerINLINE_FOOTNOTEr*   r,   REF_FOOTNOTEr/   after_render_hooksr#   rR   rS   NAMErW   ra   rZ   )rI   s    r)   r   r   x   s    2 II	   HH	     !23	{{r{{''61
^-@A
_.BC
[*:; 2{r+   )rI   r   r   N)$r:   typingr   r   r   r   r   r   corer
   utilr   block_parserr   r   r   inline_parserr   markdownr   __all__r;   _PARAGRAPH_SPLIT_FOOTNOTE_LABELrj   ri   r<   intr*   r/   rH   rR   rW   rZ   ra   r   rY   r+   r)   <module>rw      s   	 ? ?  *0,#-2::i(  0./2		  +_<vE. U3Z  Z]  	m 	c
 	: 	RU 	b} b3 bs b: bZ^_bdg_gZh b6!#tDcN';";<EO
3T#s(^$$%@. @s @3 @3 @P~ PS PS P7> 7 73 7s 7WZ 7*<r+   