
    c                         d dl 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 	 	 	 	 	 	 	 ddedededeeegef                  dedededefdZdee         deegef         dedededefdZdefdZdedefdZdS )    N)CallableListOptionalSet)
MarkdownIt)	StateCore)Token      F   ¶Tmd	min_level	max_level	slug_func	permalinkpermalinkSymbolpermalinkBeforepermalinkSpacec                     t          t          ||dz                       }| j        j                            dt          ||pt          ||||                     dS )u  Plugin for adding header anchors, based on
    `markdown-it-anchor <https://github.com/valeriangalliat/markdown-it-anchor>`__

    .. code-block:: md

        # Title String

    renders as:

    .. code-block:: html

        <h1 id="title-string">Title String <a class="header-anchor" href="#title-string">¶</a></h1>

    :param min_level: minimum header level to apply anchors
    :param max_level: maximum header level to apply anchors
    :param slug_func: function to convert title text to id slug.
    :param permalink: Add a permalink next to the title
    :param permalinkSymbol: the symbol to show
    :param permalinkBefore: Add the permalink before the title, otherwise after
    :param permalinkSpace: Add a space between the permalink and the title

    Note, the default slug function aims to mimic the GitHub Markdown format, see:

    - https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/toc_filter.rb
    - https://gist.github.com/asabaylus/3071099

    r
   anchorN)listrangecorerulerpush_make_anchors_funcslugify)	r   r   r   r   r   r   r   r   selected_levelss	            =lib/python3.11/site-packages/mdit_py_plugins/anchors/index.pyanchors_pluginr    	   sm    J 5IM::;;OGM 	
 	

 
 
 
 
    r   c                 V     t                      dt          f fd}|S )Nstatec           	         t          | j                  D ]c\  }}|j        dk    rt          |j        d                   }|vr1| j        |dz            }|j        J d                    d |j        D                       }t           |                    }|                    d|           	rt          ddd          }|                    dd	           |                    d
d|            |t          ddd          t          ddd          g}
r*|rt          dddd          gng z   |j        z   |_        0|j        
                    rt          dddd          gng |z              ed S )Nheading_openr
    c              3   6   K   | ]}|j         d v |j        V  dS ))textcode_inlineN)typecontent).0childs     r   	<genexpr>z;_make_anchors_func.<locals>._anchor_func.<locals>.<genexpr>O   sF        :!88     r!   id	link_openaclasszheader-anchorhref#
html_blockr   )r+   
link_closer(    )	enumeratetokensr*   inttagchildrenjoinunique_slugattrSetr	   extend)r#   idxtokenlevelinline_tokentitleslugr0   link_tokensr   r   r   r   r   r   slugss            r   _anchor_funcz(_make_anchors_func.<locals>._anchor_funcF   s   %el33 +	 +	LS%z^+ 	!%%EO+  <a0L(444GG  )2    E
 yy//77DMM$%%% ! 	
 !!'?;;;!!&*d**555,AGGG,R00
 # #  .$U62q#>>>??!#	 '/0 !)) !)00@NV%As;;;<<TV%&  Q+	 +	r!   )setr   )r   r   r   r   r   r   rJ   rI   s   `````` @r   r   r   <   s`     eeE,I , , , , , , , , , , , ,\ r!   rF   c                     t          j        dd|                                                                                     dd                    S )Nz[^\w\u4e00-\u9fff\- ]r&   r8   -)resubstriplowerreplace)rF   s    r   r   r   w   s<    6*B0C0C0E0E0M0McSV0W0WXXXr!   rG   rI   c                 `    | }d}||v r|  d| }|dz  }||v |                     |           |S )Nr
   rM   )add)rG   rI   uniqis       r   r?   r?   {   sT    D	A
%- }}}}	Q %-  
IIdOOOKr!   )r
   r   NFr   FT)rN   typingr   r   r   r   markdown_itr   markdown_it.rules_corer   markdown_it.tokenr	   r;   strboolr    r   r   rK   r?    r!   r   <module>r^      s   				 0 0 0 0 0 0 0 0 0 0 0 0 " " " " " " , , , , , , # # # # # #
 04!0 000 0 #,-	0
 0 0 0 0 0 0 0f8#Y8s
#8 8 	8
 8 8 8 8 8vY3 Y Y Y Yc #      r!   