%PDF- %PDF-
Mini Shell

Mini Shell

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

�

���eh���dZddlmZddlZddlZddlmcmZddlm	Z	m
Z
ddlmZddl
mZe	rddlmZej"d	�Zd#d
�ZGd�d�ZGd
�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�d e�ZGd!�d"e�Zy)$a;
A block processor parses blocks of text and adds new elements to the ElementTree. Blocks of text,
separated from other text by blank lines, may have a different syntax and produce a differently
structured tree than other Markdown. Block processors excel at handling code formatting, equation
layouts, tables, etc.
�)�annotationsN)�
TYPE_CHECKING�Any�)�util)�BlockParser)�Markdown�MARKDOWNc�`�t|�}|jjt|�dd�|jjt	|�dd�|jjt|�dd�|jjt
|�dd�|jjt|�d	d
�|jjt|�dd�|jjt|�d
d�|jjt|�dd�|jjt|�dd�|jjt|�dd�|jjt|�dd�|S)z2 Build the default block parser used by Markdown. �empty�d�indent�Z�code�P�
hashheader�F�setextheader�<�hr�2�olist�(�ulist��quote��	reference��	paragraph�
)r�blockprocessors�register�EmptyBlockProcessor�ListIndentProcessor�CodeBlockProcessor�HashHeaderProcessor�SetextHeaderProcessor�HRProcessor�OListProcessor�UListProcessor�BlockQuoteProcessor�ReferenceProcessor�ParagraphProcessor)�md�kwargs�parsers   �:/usr/lib/python3/dist-packages/markdown/blockprocessors.py�build_block_parserr3*sX��
��_�F�
���#�#�$7��$?��#�N�
���#�#�$7��$?��2�N�
���#�#�$6�v�$>���K�
���#�#�$7��$?��r�R�
���#�#�$9�&�$A�>�SU�V�
���#�#�K��$7��r�B�
���#�#�N�6�$:�G�R�H�
���#�#�N�6�$:�G�R�H�
���#�#�$7��$?��"�M�
���#�#�$6�v�$>��R�P�
���#�#�$6�v�$>��R�P��M�c�D�eZdZdZd	d�Zd
d�Zddd�Zd
dd�Zdd�Zdd�Z	y)�BlockProcessoraY Base class for block processors.

    Each subclass will provide the methods below to work with the source and
    tree. Each processor will need to define it's own `test` and `run`
    methods. The `test` method should return True or False, to indicate
    whether the current block should be processed by this processor. If the
    test passes, the parser will call the processors `run` method.

    Attributes:
        BlockProcessor.parser (BlockParser): The `BlockParser` instance this is attached to.
        BlockProcessor.tab_length (int): The tab length set on the `Markdown` instance.

    c�H�||_|jj|_y�N)r1r/�
tab_length)�selfr1s  r2�__init__zBlockProcessor.__init__Js����� �)�)�.�.��r4c�$�t|�r|dSy)z. Return the last child of an `etree` element. ���N)�len)r:�parents  r2�	lastChildzBlockProcessor.lastChildNs���v�;��"�:��r4Nc�F�|�|j}g}|jd�}|D]N}|jd|z�r|j||d��,|j	�s|jd��Nndj|�dj|t
|�d�fS)z= Remove a tab from the front of each line of the given text. N�
� �)r9�split�
startswith�append�strip�joinr>)r:�text�length�newtext�lines�lines      r2�detabzBlockProcessor.detabUs����>��_�_�F����
�
�4� ���	�D����s�V�|�,����t�F�G�}�-��Z�Z�\����r�"��
	��y�y��!�4�9�9�U�3�w�<�=�-A�#B�B�Br4c���|jd�}tt|��D]?}||jd|jz|z�s�(|||j|zd||<�Adj|�S)z? Remove a tab from front of lines but allowing dedented lines. rBrCN)rE�ranger>rFr9rI)r:rJ�levelrM�is     r2�
looseDetabzBlockProcessor.looseDetabdsw���
�
�4� ���s�5�z�"�	<�A��Q�x�"�"�3�t���#6�u�#<�=� ��8�D�O�O�E�$9�$:�;��a��	<��y�y���r4c��y)aZ Test for block type. Must be overridden by subclasses.

        As the parser loops through processors, it will call the `test`
        method on each to determine if the given block of text is of that
        type. This method must return a boolean `True` or `False`. The
        actual method of testing is left to the needs of that particular
        block type. It could be as simple as `block.startswith(some_string)`
        or a complex regular expression. As the block type may be different
        depending on the parent of the block (i.e. inside a list), the parent
        `etree` element is also provided and may be used as part of the test.

        Keyword arguments:
            parent: An `etree` element which will be the parent of the block.
            block: A block of text from the source which has been split at blank lines.
        N��r:r?�blocks   r2�testzBlockProcessor.testls�� 	
r4c��y)a3 Run processor. Must be overridden by subclasses.

        When the parser determines the appropriate type of a block, the parser
        will call the corresponding processor's `run` method. This method
        should parse the individual lines of the block and append them to
        the `etree`.

        Note that both the `parent` and `etree` keywords are pointers
        to instances of the objects which should be edited in place. Each
        processor must make changes to the existing objects as there is no
        mechanism to return new/different objects to replace them.

        This means that this method should be adding `SubElements` or adding text
        to the parent, and should remove (`pop`) or add (`insert`) items to
        the list of blocks.

        If `False` is returned, this will have the same effect as returning `False`
        from the `test` method.

        Keyword arguments:
            parent: An `etree` element which is the parent of the current block.
            blocks: A list of all remaining blocks of the document.
        NrV)r:r?�blockss   r2�runzBlockProcessor.run~s��0	
r4�r1r)r?�
etree.Element�returnzetree.Element | Noner8)rJ�strrKz
int | Noner_ztuple[str, str])r)rJr`rR�intr_r`�r?r^rXr`r_�bool)r?r^r[�	list[str]r_zbool | None)
�__name__�
__module__�__qualname__�__doc__r;r@rOrTrYr\rVr4r2r6r6;s&���/��
C� �
�$
r4r6c�T��eZdZdZdgZ	ddgZ	�fd�Zd
d�Zdd�Zdd�Z	d
d	�Z
�xZS)r%z� Process children of list items.

    Example

        * a list item
            process this part

            or this part

    �li�ul�olc�l��t�|�|�tjd|jz�|_y)Nz
^(([ ]{%s})+))�superr;�re�compiler9�	INDENT_RE)r:�args�	__class__s  �r2r;zListIndentProcessor.__init__�s*���
���$�����$4�t���$F�G��r4c�(�|jd|jz�xrs|jjj	d�xrK|j
|jvxs1t|�xr$|dduxr|dj
|jvS)NrC�detabbedr=)	rFr9r1�state�isstate�tag�
ITEM_TYPESr>�
LIST_TYPESrWs   r2rYzListIndentProcessor.test�s�������D�O�O� 3�4�:����!�!�)�)�*�5�5�:�
�Z�Z�4�?�?�
*�9��V��8����4�!7�8��B�Z�^�^�t���6�		:r4c���|jd�}|j||�\}}|j||�}|jjjd�|j|jvrft|�r=|dj|jvr"|jj|d|g��n|jj||g�n�|j|jvr|jj||g�n�t|�r�|dj|jvrw|djrHtjd�}|dj|_d|d_|djd|�|jj|d|�n|j!||�|jjj#�y)Nrrur=�prD)�pop�	get_levelrTr1rv�setrxryr>rz�parseBlocksrJ�etree�Element�insert�
parseChunk�create_item�reset)r:r?r[rXrR�siblingr|s       r2r\zListIndentProcessor.run�sw���
�
�1�
�������6���w�����u�-���������j�)��:�:����(��6�{�v�b�z�~�~����@����'�'��r�
�U�G�<����'�'����8�
�[�[�D�O�O�
+��K�K�#�#�G�e�W�5�
��\�g�b�k�o�o����@��r�{����M�M�#�&�� ���)�)���#%���� ����"�"�1�a�(��K�K�"�"�7�2�;��6����W�e�,��������!r4c�j�tj|d�}|jj||g�y)z> Create a new `li` and parse the block with it as the parent. rjN)r��
SubElementr1r�)r:r?rXrjs    r2r�zListIndentProcessor.create_item�s*��
�
�
�f�d�
+��������U�G�,r4c���|jj|�}|r(t|jd��|jz}nd}|j
jjd�rd}nd}||kDrn|j|�}|�P|j|jvs|j|jvr |j|jvr|dz
}|}n	||fS||kDr�n||fS)z/ Get level of indentation based on list level. rr�list)rq�matchr>�groupr9r1rvrwr@rxrzry)r:r?rX�m�indent_levelrR�childs       r2r~zListIndentProcessor.get_level�s���
�N�N� � ��'����q�w�w�q�z�?�4�?�?�:�L��L��;�;���$�$�V�,��E��E��U�"��N�N�6�*�E��!��	�	�T�_�_�,��	�	�T�_�_�0L��9�9����/��Q�J�E�����f�}���U�"��f�}�r4rb�r?r^r[rdr_�None)r?r^rXr`r_r�)r?r^rXr`r_ztuple[int, etree.Element])rerfrgrhryrzr;rYr\r�r~�
__classcell__�rss@r2r%r%�s;���	���J�-����J�9�H�:�""�H-�
r4r%c� �eZdZdZdd�Zdd�Zy)r&z Process code blocks. c�>�|jd|jz�S)NrC)rFr9rWs   r2rYzCodeBlockProcessor.test�s������D�O�O� 3�4�4r4c	��|j|�}|jd�}d}|��|jdk(r�t|�r�|djdk(ro|d}|j	|�\}}tjdj|jtj|j����|_n~tj|d�}tj|d�}|j	|�\}}tjdtj|j��z�|_|r|jd|�yy)NrrD�prerz{}
{}
z%s
)r@r}rxr>rOr�AtomicString�formatrJ�code_escape�rstripr�r�r�)r:r?r[r�rX�theRestrr�s        r2r\zCodeBlockProcessor.runs���.�.��(���
�
�1�
������G�K�K�5�$8��w�<�G�A�J�N�N�f�4��1�:�D�!�Z�Z��.�N�E�7��)�)��!�!�$�)�)�T�-=�-=�e�l�l�n�-M�N��D�I�
�"�"�6�5�1�C��#�#�C��0�D�!�Z�Z��.�N�E�7��)�)�&�4�3C�3C�E�L�L�N�3S�*S�T�D�I��
�M�M�!�W�%�	r4Nrbr��rerfrgrhrYr\rVr4r2r&r&�s�� �5�&r4r&c�L�eZdZdZej
d�Zdd�Zdd�Zd	d�Z	y)
r,z Process blockquotes. z(^|\n)[ ]{0,3}>[ ]?(.*)c�x�t|jj|��xrtj�Sr8)rc�RE�searchr�nearing_recursion_limitrWs   r2rYzBlockQuoteProcessor.test!s+���D�G�G�N�N�5�)�*�Q�4�3O�3O�3Q�/Q�Qr4c��|jd�}|jj|�}|r~|d|j�}|jj||g�dj
||j�djd�D�cgc]}|j|���c}�}|j|�}|�|jdk(r|}ntj|d�}|jjjd�|jj||�|jjj!�ycc}w)NrrB�
blockquote)r}r�r��startr1r�rIrE�cleanr@rxr�r�rvrr�r�)	r:r?r[rXr��beforerNr�rs	         r2r\zBlockQuoteProcessor.run$s
���
�
�1�
���G�G�N�N�5�!����:�A�G�G�I�&�F��K�K�#�#�F�V�H�5��I�I�.3�A�G�G�I�J�.?�.E�.E�d�.K�L�d����D�!�L��E��.�.��(����7�;�;�,�#>��E��$�$�V�\�:�E�	
�������l�+������u�e�,��������!��Ms�Ec��|jj|�}|j�dk(ry|r|jd�S|S)z& Remove `>` from beginning of a line. �>rD�)r�r�rHr�)r:rNr�s   r2r�zBlockQuoteProcessor.clean<s;���G�G�M�M�$����:�:�<�3���
��7�7�1�:���Kr4Nrbr�)rNr`r_r`)
rerfrgrhrorpr�rYr\r�rVr4r2r,r,s&�� �	����.�	/�B�R�"�0r4r,c���eZdZUdZdZded<	dZded<	dZded	<	dd
gZded<	d�fd
�Z	dd�Z
dd�Zdd�Z�xZ
S)r*z Process ordered list blocks. rlr`�TAG�1�
STARTSWITHTrc�LAZY_OLrkrd�SIBLING_TAGSc�>��t�|�|�tjd|jdz
z�|_tjd|jdz
z�|_tjd|j|jdzdz
fz�|_y)Nz^[ ]{0,%d}\d+\.[ ]+(.*)rz!^[ ]{0,%d}((\d+\.)|[*+-])[ ]+(.*)z ^[ ]{%d,%d}((\d+\.)|[*+-])[ ]+.*r�)rnr;rorpr9r��CHILD_RErq�r:r1rss  �r2r;zOListProcessor.__init__Ys����
���� ��*�*�7�4�?�?�Q�;N�O�P����
�
�#G�$(�O�O�a�$7�$9�:��
����$G�%)�_�_�d�o�o��6I�A�6M�$N�%O�P��r4c�J�t|jj|��Sr8�rcr�r�rWs   r2rYzOListProcessor.testd����D�G�G�M�M�%�(�)�)r4c�|�|j|jd��}|j|�}|��a|j|jv�rH|}|dj
rHt
jd�}|dj
|_d|d_|djd|�|j|d�}|�K|jr?t
j|dd�}|jj�|_d|_	t
j|d�}|jjjd�|jd�}	|jj||	g�|jjj!�ne|jdvr|}nTt
j||j"�}|j$s(|j&dk7r|j&|j(d	<|jjjd
�|D]t}
|
j+d|j,z�r!|jj|d|
g��Bt
j|d�}|jj||
g��v|jjj!�y)Nrr=r|rDrj�	looselist)rlrkr�r�r�rC)�	get_itemsr}r@rxr�rJr�r�r��tailr��lstripr1rvrr�r�r�r�r��attribrFr9)r:r?r[�itemsr��lstr|�lchrj�	firstitem�items           r2r\zOListProcessor.rungs'�����v�z�z�!�}�-���.�.��(����7�;�;�$�2C�2C�#C��C��2�w�|�|��M�M�#�&���R������!��B����B����q�!�$��.�.��R��)�C���3�8�8��$�$�S��W�c�2�������*�������!�!�#�t�,�B��K�K���!�!�+�.��	�	�!��I��K�K�#�#�B���4��K�K���#�#�%�
�Z�Z�<�
'��C��"�"�6�4�8�8�4�C��<�<�D�O�O�s�$:�&*�o�o��
�
�7�#��������f�%��	4�D����s�4�?�?�2�3����'�'��B��$��8��%�%�c�4�0�����'�'��T�F�3�	4�	
�������!r4c�h�g}|jd�D�]}|jj|�}|rz|sW|jdk(rHt	j
d�}|j|j
d��j
�|_|j|j
d����|jj|�rM|djd|jz�rdj|d|�|d<��|j|���dj|d|�|d<��|S)	z  Break a block into list items. rBrlz(\d+)r�r=rC�{}
{})
rEr�r�r�rorpr�r�rGrqrFr9r�)r:rXr�rNr��
INTEGER_REs      r2r�zOListProcessor.get_items�s������K�K��%�	=�D��
�
�#�#�D�)�A������T�!1�!#���H�!5�J�&0�&6�&6�q�w�w�q�z�&B�&H�&H�&J�D�O����Q�W�W�Q�Z�(����%�%�d�+���9�'�'��D�O�O�(;�<� (����b�	�4� @�E�"�I��L�L��&�%�O�O�E�"�I�t�<��b�	�)	=�*�r4r]rbr�)rXr`r_rd)rerfrgrhr��__annotations__r�r�r�r;rYr\r�r�r�s@r2r*r*GsY���(��C��O�6��J�����G�T��*�#�T�l�L�)�*��
	P�*�9"�vr4r*c�6��eZdZUdZdZded<	d�fd�Z�xZS)r+z  Process unordered list blocks. rkr`r�c�x��t�|�|�tjd|jdz
z�|_y)Nz^[ ]{0,%d}[*+-][ ]+(.*)r)rnr;rorpr9r�r�s  �r2r;zUListProcessor.__init__�s/���
���� ��*�*�7�4�?�?�Q�;N�O�P��r4r])rerfrgrhr�r�r;r�r�s@r2r+r+�s���*��C��O�6�Q�Qr4r+c�D�eZdZdZej
d�Zdd�Zdd�Zy)r'z Process Hash Headers. z>(?:^|\n)(?P<level>#{1,6})(?P<header>(?:\\.|[^\\])*?)#*(?:\n|$)c�J�t|jj|��Sr8)rcr�r�rWs   r2rYzHashHeaderProcessor.test�s���D�G�G�N�N�5�)�*�*r4c	���|jd�}|jj|�}|r�|d|j�}||j	�d}|r|j
j
||g�tj|dt|jd��z�}|jd�j�|_|r|jd|�yytjd|z�y)Nr�h%drR�headerzWe've got a problem header: %r)r}r�r�r��endr1r�r�r�r>r�rHrJr��logger�warn)r:r?r[rXr�r��after�hs        r2r\zHashHeaderProcessor.run�s����
�
�1�
���G�G�N�N�5�!����:�A�G�G�I�&�F��!�%�%�'�(�O�E�����'�'����9�� � ����Q�W�W�W�5E�1F�)F�G�A��W�W�X�&�,�,�.�A�F���
�
�a��'��

�K�K�8�5�@�Ar4Nrbr�)	rerfrgrhrorpr�rYr\rVr4r2r'r'�s#��!�
����U�	V�B�+�Br4r'c�Z�eZdZdZej
dej�Zdd�Zdd�Z	y)r(z Process Setext-style Headers. z^.*?\n[=-]+[ ]*(\n|$)c�J�t|jj|��Sr8r�rWs   r2rYzSetextHeaderProcessor.test�r�r4c�>�|jd�jd�}|djd�rd}nd}tj|d|z�}|dj�|_t|�dkDr%|jddj|dd��yy)NrrBr�=r�r�)
r}rErFr�r�rHrJr>r�rI)r:r?r[rMrRr�s      r2r\zSetextHeaderProcessor.run�s����
�
�1�
�#�#�D�)����8���s�#��E��E����V�U�U�]�3���q����!����u�:��>��M�M�!�T�Y�Y�u�Q�R�y�1�2�r4Nrbr��
rerfrgrhrorp�	MULTILINEr�rYr\rVr4r2r(r(�s(��)�
����,�b�l�l�	;�B�*�3r4r(c�^�eZdZdZdZejeej�Zdd�Z	dd�Z
y)r)z Process Horizontal Rules. zf^[ ]{0,3}(?=(?P<atomicgroup>(-+[ ]{0,2}){3,}|(_+[ ]{0,2}){3,}|(\*+[ ]{0,2}){3,}))(?P=atomicgroup)[ ]*$c�N�|jj|�}|r||_yy)NTF)�	SEARCH_REr�r�)r:r?rXr�s    r2rYzHRProcessor.tests&���N�N�!�!�%�(����D�J��r4c�Z�|jd�}|j}|d|j�jd�}|r|jj||g�t
j|d�||j�djd�}|r|jd|�yy)NrrBr)r}r�r�r�r1r�r�r�r�r�r�)r:r?r[rXr��prelines�	postliness       r2r\zHRProcessor.runs����
�
�1�
���
�
����%�+�+�-�(�/�/��5����K�K�#�#�F�X�J�7�
�����&��%�)�)�+�,�'�.�.�t�4�	���M�M�!�Y�'�r4Nrbr�)rerfrgrhr�rorpr�r�rYr\rVr4r2r)r)�s-��%�
s�B���
�
�2�r�|�|�,�I��(r4r)c� �eZdZdZdd�Zdd�Zy)r$z< Process blocks that are empty or start with an empty line. c�.�|xs|jd�S)NrB)rFrWs   r2rYzEmptyBlockProcessor.test$s���y�2�E�,�,�T�2�2r4c�^�|jd�}d}|rd}|dd}|r|jd|�|j|�}|�j|jdk(rZt	|�rN|djdk(r;tjdj|dj|��|d_yyyyy)Nrz

rBrr�rz{}{})	r}r�r@rxr>rr�r�rJ)r:r?r[rX�fillerr�r�s       r2r\zEmptyBlockProcessor.run's����
�
�1�
������F��A�B�i�G���
�
�a��)��.�.��(����G�K�K�5�$8��w�<�G�A�J�N�N�f�4�"�/�/��
�
�g�a�j�o�o�v�6��G�A�J�O�5�<�%9�r4Nrbr�r�rVr4r2r$r$!s��F�3�r4r$c�Z�eZdZdZej
dej�Zdd�Zdd�Z	y)r-z Process link references. z\^[ ]{0,3}\[([^\[\]]*)\]:[ ]*\n?[ ]*([^\s]+)[ ]*(?:\n[ ]*)?((["\'])(.*)\4[ ]*|\((.*)\)[ ]*)?$c��y�NTrVrWs   r2rYzReferenceProcessor.testB���r4c��|jd�}|jj|�}|�rL|jd�j	�j�}|jd�j
d�jd�}|jd�xs|jd�}||f|jjj|<||j�dj	�r2|jd||j�dj
d��|d|j�j	�r2|jd|d|j�jd��y	|jd|�y
)Nrrr��<r���rBTF)r}r�r�r�rH�lowerr�r�r1r/�
referencesr�r�r�)r:r?r[rXr��id�link�titles        r2r\zReferenceProcessor.runEs,���
�
�1�
���G�G�N�N�5�!��������!�!�#�)�)�+�B��7�7�1�:�$�$�S�)�0�0��5�D��G�G�A�J�,�!�'�'�!�*�E�-1�5�M�D�K�K�N�N�%�%�b�)��Q�U�U�W�X��$�$�&��
�
�a��q�u�u�w�x��!7�!7��!=�>��Z�a�g�g�i� �&�&�(��
�
�a��z����	�!2�!9�!9�$�!?�@���
�
�a���r4Nrb)r?r^r[rdr_rcr�rVr4r2r-r-<s+��$�	����g�ik�iu�iu�
�B��r4r-c� �eZdZdZdd�Zdd�Zy)r.z Process Paragraph blocks. c��yr�rVrWs   r2rYzParagraphProcessor.test\r�r4c��|jd�}|j�r�|jjj	d�r�|j|�}|�9|jr"dj|j|�|_yd|z|_y|jr"dj|j|�|_y|j�|_ytj|d�}|j�|_yy)Nrr�r�z
%sr|)r}rHr1rvrwr@r�r�rJr�r�r�)r:r?r[rXr�r|s      r2r\zParagraphProcessor.run_s����
�
�1�
���;�;�=��{�{� � �(�(��0��.�.��0���&��|�|�'/���w�|�|�U�'K���'-��~����{�{�&.�o�o�f�k�k�5�&I���&+�l�l�n����$�$�V�S�1��������7r4Nrbr�r�rVr4r2r.r.Ys��%��(r4r.)r/r	r0rr_r) rh�
__future__r�loggingro�xml.etree.ElementTreer��ElementTree�typingrrrDr�blockparserr�markdownr	�	getLoggerr�r3r6r%r&r,r*r+r'r(r)r$r-r.rVr4r2�<module>r�s���(�#��	�%�%�%��$��!�	��	�	�:�	&���"[
�[
�|_�.�_�D&��&�B(�.�(�Vs�^�s�l	Q�^�	Q�B�.�B�>3�N�3�.(�.�(�D�.��6���:#(��#(r4

Zerion Mini Shell 1.0