%PDF- %PDF-
Mini Shell

Mini Shell

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

�

���e�D����dZddlmZddlZddlmcmZddlmZm	Z	ddl
mZddl
mZerddl
mZdd	�Zdd
�ZGd�dej"�ZGd
�de�ZGd�de�ZGd�de�Zy)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���tj�}|jt|�dd�|jt	|�dd�|jt|�dd�|S)z3 Build the default  `treeprocessors` for Markdown. �inline��prettify�
�unescaper)r�Registry�register�InlineProcessor�PrettifyTreeprocessor�UnescapeTreeprocessor)�md�kwargs�treeprocessorss   �9/usr/lib/python3/dist-packages/markdown/treeprocessors.py�build_treeprocessorsr'sZ���]�]�_�N����O�B�/��2�>����1�"�5�z�2�F����1�"�5�z�1�E���c�X�t|tj�st|t�Sy)z_ Return `True` if object is a string but not an  [`AtomicString`][markdown.util.AtomicString]. F)�
isinstancer�AtomicString�str)�ss r�isStringr 0s"���a��*�*�+��!�S�!�!�rc��eZdZdZdd�Zy)�
Treeprocessora
    `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��y)a
        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`.
        N�)�self�roots  r�runzTreeprocessor.runAs��	
rN)r&�
etree.Element�return�etree.Element | None)�__name__�
__module__�__qualname__�__doc__r'r$rrr"r"7s���
rr"c��eZdZdZd
d�Zdd�Zdd�Zdd�Zddd�Zddd�Z		d							dd�Z
	d									dd	�Zdd
�Zddd�Z
y)rzL
    A `Treeprocessor` that traverses a tree, applying inline patterns.
    c�&�tj|_tj|_dt|j�zt|j�z|_tj|_||_	|j|_
g|_y)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%rs  r�__init__zInlineProcessor.__init__Psr��$(�$B�$B��!�$(�H�H��!�$%��D�,E�,E�(F�$F�(+�D�,E�,E�(F�%G��!� $� :� :������ �/�/���$&��rc�`�dt|j�z}tj|z}||fS)z Generate a placeholder z%04d)r6�
stashed_nodesr�INLINE_PLACEHOLDER)r%�type�id�hashs    r�__makePlaceholderz!InlineProcessor.__makePlaceholderZs0��
�c�$�,�,�-�
-���&�&��+���R�x�rc��|jj||�}|r!|jd�|j�fSd|dzfS)a
        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.

        rN)r9�search�group�end)r%�data�index�ms    r�__findPlaceholderz!InlineProcessor.__findPlaceholder`sF��
�!�!�(�(��u�5����7�7�1�:�q�u�u�w�&�&�����?�"rc�L�|j|�\}}||j|<|S)z Add node to stash. )�!_InlineProcessor__makePlaceholderr>)r%�noder@�placeholderrAs     r�__stashNodezInlineProcessor.__stashNoders,���0�0��6���R�!%����2���rc���t|tj�sNd}t|j�}||kr2|j|j||||�\}}}|s|dz
}||kr�2|S)a
        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.

        rr)rrrr6r:�_InlineProcessor__applyPattern)r%rH�patternIndex�
startIndex�count�matcheds      r�__handleInlinezInlineProcessor.__handleInlinexs|���$�� 1� 1�2��J���+�+�,�E���&�,0�,?�,?��'�'��5�t�\�:�-�)��g�z�� �A�%�L���&��rc� �|r|j}d|_n|j}d|_|j|||�}|s"||urt|�j	|�dz}nd}|j�|D]}|j
||d��y)a'
        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.

        Nrr)�text�tail�%_InlineProcessor__processPlaceholders�listrI�reverse�insert)r%rN�subnode�isTextrY�childResult�pos�newChilds        r�__processElementTextz$InlineProcessor.__processElementText�s�����<�<�D��G�L��<�<�D��G�L��0�0��w��G���$�g�-��t�*�"�"�7�+�a�/�C��C�����#�	*�H��K�K��X�a�[�)�	*rc�l���
�d���
fd�}g�
d}|�r�|j|j|�}|dk7�r=|j||�\}}||jvr�|jj	|�}	|dkDr
|||}
||
�t|	t�s�|	gt|	�zD]u}|jr-|jj�r|j|	|d�|js�I|jj�s�d|j||��wn||	�|}��|}�
j|	|jddf�nd|t|j�z}||||�|}n>||d}
t|tj �rtj |
�}
||
�d}|r����
S)a�
        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�2��|r��r<�ddjr�ddxj|z
c_y|�dd_y�s*�jr�xj|z
c_y|�_y�jr�xj|z
c_y|�_yy)N���r)rZrY)rYr`�parent�results ���r�linkTextz7InlineProcessor.__processPlaceholders.<locals>.linkText�s�������b�z�!�}�)�)��r�
�1�
�*�*�d�2�*�-1��r�
�1�
�*���{�{����t�+��&*����{�{����t�+��&*���rrrgFN�)rY�
str | Noner)�None)�findr3�!_InlineProcessor__findPlaceholderr>�getrrr\rZ�strip�$_InlineProcessor__processElementTextrY�appendr;r6rr)r%rHrhr`rj�strartIndexrIrA�
phEndIndexrNrY�childrGris  ``         @r�__processPlaceholdersz%InlineProcessor.__processPlaceholders�s����$	+�"������I�I�d�7�7��E�E���{�!%�!7�!7��e�!D���J���+�+�+��-�-�1�1�"�5�D��q�y�#�K��6�� ���%�d�C�0�&*�V�d�4�j�%8�L�E�$�z�z�#(�:�:�#3�#3�#5�$(�$=�$=�(,�e�U�%&� %�z�z�#(�:�:�#3�#3�#5�$(�$=�$=�e�U�$K�L�!���&0�� �",�K��M�M�4�����):�";�<� �#�d�&?�&?�"@�@�C��T�+�c�2�3�"%�K��K�L�)���d�D�$5�$5�6��,�,�T�2�D������Q�T�
rc��t|tj�}|jD]%}|j	�|j
vs� |ddfcS|rZd}|j
�j||�D]4}|j||�\}}	}
|	�|
�||jd�z
}d}�4n)n'|j
�j||d�}|d|}|s|ddfS|s3|j|�}|jd�}	|jd�}
�|d
fSt|t�s�t|jtj�s�|gt!|�zD]�}t#|�r�|jrq|j
j%|j&j	��|j)|j|dz�|_
|j
j+�|j,s��|j)|j,|�|_��|j/||j1��}
|rdj3|d	|
|
d�ddfSdj3|j5d�|
|j7�d�ddfS)	a�
        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.

        FrNTrz{}{}{}z{}{}{}{}rg)rrr�ANCESTOR_EXCLUDES�lowerr;�getCompiledRegExp�finditer�handleMatchrG�match�startrrYrrr\r rs�tag�_InlineProcessor__handleInline�poprZ�_InlineProcessor__stashNoder@�formatrF�groups)r%�patternrHrSrT�	new_style�excluder~rNrrG�leftDatarvrOs              r�__applyPatternzInlineProcessor.__applyPattern�sw��*�w��(F�(F�G�	��0�0�	&�G��}�}��$�.�.�0��U�A�~�%�	&���E�!�2�2�4�=�=�d�J�O�
��#*�#6�#6�u�d�#C� ��e�S��=�C�K��%�)�)�A�,�.�J� �E���

��-�-�/�5�5�d�:�;�6G�H�E��K�Z�(�H�����>�!���&�&�u�-�D��K�K��N�E��)�)�A�,�C��<���s�?�"��$��$��d�i�i��):�):�;�"�V�d�4�j�0��E�#�D�>� �:�:� �N�N�1�1�%�)�)�/�/�2C�D�)-�)<�)<� %�
�
�L�1�,<�*�E�J�!�N�N�.�.�0� �:�:�)-�)<�)<� %�
�
�L�*�E�J���&�&�t�W�\�\�^�<����?�?�4���<�#.��S�T�
�<�=A�1�E�
E��$�$�X�%*�[�[��^�%0�%�,�,�.��2D�F�GK�Q�O�
Orc���g}|�I|�)|j|jj��|jj	|�}|��I|j�|j
|�y)zBuild the ancestor list.N)rsr�rz�
parent_maprpr]�extend)r%rh�parentsr;s    r�__build_ancestorsz!InlineProcessor.__build_ancestorsMsd���	�� ��!�� � ����!1�!1�!3�4��_�_�(�(��0�F�� �	�������y�!rNc�f�i|_|�gn|dd}|j�D��cic]}|D]}||���c}}|_||fg}|�re|j�\}}||_|j||j�g}	|D�]�}
|
jr�t|
jtj�s�|jj|
jj��|
j}d|
_|j|j|�|
�}|D]}
|
|j|
d<�||z
}|	j|
|f�|jj�|
jr�|j|
j�}t!j"d�}d|
_|j||d�}|jr|j|
_t%|�j'|
�dz}|j)�|D])}||j|d<|j+||d��+t-|
�s���||j|
<|j|
|jddf����|	D]/\}}t/|�D]\}}|d}|j+||���1|r��e|Scc}}w)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�dFr)r>�iterr�r�r;�!_InlineProcessor__build_ancestorsrYrrrrsr�rzr[r�rZ�etree�Elementr\rIr]r^r6�	enumerate)r%�treer;�tree_parents�p�c�stack�currElementr��insertQueuervrY�lst�itemrZ�dumby�
tailResultrbrc�element�i�objs                      rr'zInlineProcessor.runWs���$>@���'�.�r�I�a�L��)-����@�A�a�@��1�a�4�@�1�@�����%�&���#(�9�9�;� �K��$�D�N��"�"�;����?��K�$�
=���:�:�j��J�J�� 1� 1�'��N�N�)�)�%�)�)�/�/�*;�<� �:�:�D�!%�E�J��4�4��+�+�D�1�5��C�!$�9��38�����Q��0�9��S�L�E��&�&��s�|�4��N�N�&�&�(��:�:��.�.�u�z�z�:�D�!�M�M�#�.�E�!%�E�J�!%�!;�!;�D�%��!O�J��z�z�%*�Z�Z��
��{�+�1�1�%�8�1�<�C��&�&�(�$.�=��7B�������4�#�*�*�3����<�=��u�:�-8�D�O�O�E�*��L�L�%�����):�!;�<�;
=�>!,�
0����'��n�0�F�A�s�"�1�v�H��N�N�1�h�/�0�
0�M�T���[As�J-)rr	)r@rr)ztuple[str, str])rHrrI�intr)ztuple[str | None, int])rNzetree.Element | strr@rr)r)r)rHrrSr�r)r)T)rNr(r_r(r`�boolr)rm)rHrlrhr(r`r�r)z%list[tuple[etree.Element, list[str]]])
r�zinlinepatterns.PatternrHrrSr�rTr�r)ztuple[str, bool, int])rhr*r�z	list[str]r)rm�N)r�r(r;zlist[str] | Noner)r()r+r,r-r.r<rMror�r�rrr[rRr�r'r$rrrrKs����'��#�$��.*�B�	O��O��O��	O�

/�O�l�NO�'�NO��NO��	NO�
�NO�
�
NO�`"�Errc� �eZdZdZdd�Zdd�Zy)rz' Add line breaks to the html document. c��d}|jj|j�r�|jdvr�|jr|jj	�s:t|�r/|jj|dj�r||_|D]9}|jj|j�s�)|j
|��;|jr|jj	�s||_yy)z8 Recursively add line breaks to `ElementTree` children. �
)�code�prerN)r�is_block_levelr�rYrqr6�_prettifyETreerZ)r%�elemr��es    rr�z$PrettifyTreeprocessor._prettifyETree�s���
���7�7�!�!�$�(�(�+�����0O��I�I�T�Y�Y�_�_�%6��D�	�d�g�g�&<�&<�T�!�W�[�[�&I���	��
+���7�7�)�)�!�%�%�0��'�'��*�
+��y�y��	�	��� 1��D�I�!2rc���|j|�|jd�}|D]D}|jr|jj�sd|_�1d|jz|_�F|jd�}|D]t}t	|�s�|dj
dk(s�"|d}t	|�r�3|j��@tj|jj�dz�|_�vy)z7 Add line breaks to `Element` object and its children. �brr�z
%sr�rr�N)
r�r�rZrqr6r�rYrr�rstrip)r%r&�brsr��presr�r�s       rr'zPrettifyTreeprocessor.run�s���	
���D�!��i�i��o���	+�B��7�7�"�'�'�-�-�/���� �2�7�7�*���		+��y�y�����	M�C��3�x�C��F�J�J�&�0��1�v���4�y�T�Y�Y�%:� $� 1� 1�$�)�)�2B�2B�2D�t�2K� L�D�I�	MrN)r�r(r)rm�r&r(r)rm)r+r,r-r.r�r'r$rrrr�s��1��Mrrc��eZdZdZej
dj
ejej��Z
dd�Zdd�Zd	d�Z
y)
rz Restore escaped chars z	{}(\d+){}c�H�tt|jd���S)Nr)�chrr�rF)r%rJs  r�	_unescapezUnescapeTreeprocessor._unescape�s���3�q�w�w�q�z�?�#�#rc�N�|jj|j|�Sr�)�RE�subr�)r%rYs  rrzUnescapeTreeprocessor.unescape�s���w�w�{�{�4�>�>�4�0�0rc�n�|j�D]�}|jr/|jdk(s |j|j�|_|jr |j|j�|_|j�D]&\}}|j
||j|���(��y)z/ Loop over all elements and unescape all text. r�N)r�rYr�rrZ�items�set)r%r&r��key�values     rr'zUnescapeTreeprocessor.run�s����I�I�K�		4�D��y�y����V�!3� �M�M�$�)�)�4��	��y�y� �M�M�$�)�)�4��	�"�j�j�l�
4�
��U�����d�m�m�E�2�3�
4�		4rN)rJz
re.Match[str]r)r)rYrr)rr�)r+r,r-r.�re�compiler�r�STXr4r�r�rr'r$rrrr�s9��!�	����L�'�'����$�(�(�;�	<�B�$�1�4rr)rr	rrr)zutil.Registry[Treeprocessor])r�objectr)r�)r.�
__future__rr��xml.etree.ElementTreer��ElementTree�typingrrrkrr�markdownr	rr �	Processorr"rrrr$rr�<module>r�sk��(�#�	�%�%�%����!���
�D�N�N�
�(Q�m�Q�h
$M�M�$M�N4�M�4r

Zerion Mini Shell 1.0