
    !Shi                       d Z ddlmZ ddlZddlZddlmc mZ ddlm	Z	m
Z
 ddlmZ ddlmZ e	rddlmZ  ej        d	          Zd)dZ G d d          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d d e          Z G d! d"e          Z G d# d$e          Z G d% d&e          Z G d' d(e          ZdS )*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MARKDOWNmdr	   kwargsr   returnr   c                   t          |           }|j                            t          |          dd           |j                            t	          |          dd           |j                            t          |          dd           |j                            t          |          dd           |j                            t          |          d	d
           |j                            t          |          dd           |j                            t          |          dd           |j                            t          |          dd           |j                            t          |          dd           |j                            t          |          dd           |j                            t          |          dd           |S )z2 Build the default block parser used by Markdown. emptyd   indentZ   codeP   
hashheaderF   setextheader<   hr2   olist(   ulist   quote   	reference   	paragraph
   )r   blockprocessorsregisterEmptyBlockProcessorListIndentProcessorCodeBlockProcessorHashHeaderProcessorSetextHeaderProcessorHRProcessorOListProcessorUListProcessorBlockQuoteProcessorReferenceProcessorParagraphProcessor)r   r   parsers      ^/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/markdown/blockprocessors.pybuild_block_parserr4   *   s   __F
##$7$?$?#NNN
##$7$?$?2NNN
##$6v$>$>KKK
##$7$?$?rRRR
##$9&$A$A>SUVVV
##K$7$7rBBB
##N6$:$:GRHHH
##N6$:$:GRHHH
##$7$?$?"MMM
##$6v$>$>RPPP
##$6v$>$>RPPPM    c                  F    e Zd ZdZddZdd	ZdddZd d!dZd"dZd#dZ	d
S )$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.

    r2   r   c                6    || _         |j        j        | _        d S N)r2   r   
tab_length)selfr2   s     r3   __init__zBlockProcessor.__init__J   s     ).r5   parentetree.Elementr   etree.Element | Nonec                4    t          |          r|d         S dS )z. Return the last child of an `etree` element. N)len)r;   r=   s     r3   	lastChildzBlockProcessor.lastChildN   s    v;; 	":4r5   Ntextstrlength
int | Nonetuple[str, str]c                   || j         }g }|                    d          }|D ]b}|                    d|z            r|                    ||d                    8|                                s|                    d           b d                    |          d                    |t          |          d                   fS )z= Remove a tab from the front of each line of the given text. N
  )r:   split
startswithappendstripjoinrB   )r;   rD   rF   newtextlineslines         r3   detabzBlockProcessor.detabU   s    >_F

4   	 	DsV|,, tFGG}----ZZ\\ r""""yy!!499U3w<<==-A#B#BBBr5   r   levelintc                   |                     d          }t          t          |                    D ]C}||                             d| j        z  |z            r||         | j        |z  d         ||<   Dd                    |          S )z? Remove a tab from front of lines but allowing dedented lines. rJ   rK   N)rM   rangerB   rN   r:   rQ   )r;   rD   rV   rS   is        r3   
looseDetabzBlockProcessor.looseDetabd   s    

4  s5zz"" 	< 	<AQx""3t#6u#<== < 8DOE$9$:$:;ayyr5   blockboolc                    dS )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=   r\   s      r3   testzBlockProcessor.testl   s	      	r5   blocks	list[str]bool | Nonec                    dS )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.
        Nr_   )r;   r=   rb   s      r3   runzBlockProcessor.run~   s	    0 	r5   r2   r   )r=   r>   r   r?   r9   )rD   rE   rF   rG   r   rH   )r   )rD   rE   rV   rW   r   rE   r=   r>   r\   rE   r   r]   )r=   r>   rb   rc   r   rd   )
__name__
__module____qualname____doc__r<   rC   rU   r[   ra   rf   r_   r5   r3   r7   r7   ;   s         / / / /   C C C C C            $     r5   r7   c                  T     e Zd ZdZdgZ	 ddgZ	  fdZddZddZddZ	ddZ
 xZS )r(   z Process children of list items.

    Example

        * a list item
            process this part

            or this part

    liulolc                v     t                      j        |  t          j        d| j        z            | _        d S )Nz^(([ ]{%s})+))superr<   recompiler:   	INDENT_RE)r;   args	__class__s     r3   r<   zListIndentProcessor.__init__   s4    $$4t$FGGr5   r=   r>   r\   rE   r   r]   c                    |                     d| j        z            oZ| j        j                            d           o:|j        | j        v p,t          |          o|d         d uo|d         j        | j        v S )NrK   detabbedrA   )	rN   r:   r2   stateisstatetag
ITEM_TYPESrB   
LIST_TYPESr`   s      r3   ra   zListIndentProcessor.test   s    DO 344 :!))*555:Z4?* 9V 84!7 8BZ^t6		:r5   rb   rc   Nonec                   |                     d          }|                     ||          \  }}|                     ||          }| j        j                            d           |j        | j        v rct          |          r7|d         j        | j	        v r#| j        
                    |d         |g           n| j        
                    ||g           n|j        | j        v r| j        
                    ||g           nt          |          r|d         j        | j        v r~|d         j        rOt          j        d          }|d         j        |_        d|d         _        |d                             d|           | j                            |d         |           n|                     ||           | j        j                                         d S )Nr   ry   rA   prL   )pop	get_levelr[   r2   rz   setr|   r}   rB   r~   parseBlocksrD   etreeElementinsert
parseChunkcreate_itemreset)r;   r=   rb   r\   rV   siblingr   s          r3   rf   zListIndentProcessor.run   s   

166wu--j))):(( 6{{ 9vbz~@@''r
UG<<<< ''8888[DO++K##GeW5555\\ 	-gbko@@ r{ ) M#&& )#% ""1a(((K""72;6666We,,,!!!!!r5   c                h    t          j        |d          }| j                            ||g           dS )z> Create a new `li` and parse the block with it as the parent. rn   N)r   
SubElementr2   r   )r;   r=   r\   rn   s       r3   r   zListIndentProcessor.create_item   s4    fd++UG,,,,,r5   tuple[int, etree.Element]c                   | j                             |          }|r+t          |                    d                    | j        z  }nd}| j        j                            d          rd}nd}||k    rP|                     |          }|2|j	        | j
        v s|j	        | j        v r|j	        | j
        v r|dz  }|}nn||k    P||fS )z/ Get level of indentation based on list level. r   r   list)ru   matchrB   groupr:   r2   rz   r{   rC   r|   r~   r}   )r;   r=   r\   mindent_levelrV   childs          r3   r   zListIndentProcessor.get_level   s     N  '' 	qwwqzz??4?:LLL;$$V,, 	EE EU""NN6**E!	T_,,	T_0L0L9//QJE  U"" f}r5   rh   r=   r>   rb   rc   r   r   )r=   r>   r\   rE   r   r   )r=   r>   r\   rE   r   r   )ri   rj   rk   rl   r}   r~   r<   ra   rf   r   r   __classcell__rw   s   @r3   r(   r(      s        	 	 J-J9H H H H H: : : :"" "" "" ""H- - - -
       r5   r(   c                  "    e Zd ZdZddZddZdS )r)   z Process code blocks. r=   r>   r\   rE   r   r]   c                <    |                     d| j        z            S )NrK   )rN   r:   r`   s      r3   ra   zCodeBlockProcessor.test   s    DO 3444r5   rb   rc   r   c           	        |                      |          }|                    d          }d}||j        dk    rt          |          r|d         j        dk    rw|d         }|                     |          \  }}t          j        d                    |j        t          j	        |
                                                              |_        nt          j        |d          }t          j        |d          }|                     |          \  }}t          j        dt          j	        |
                                          z            |_        |r|                    d|           d S d S )Nr   rL   prer   z{}
{}
z%s
)rC   r   r|   rB   rU   r   AtomicStringformatrD   code_escaperstripr   r   r   )r;   r=   rb   r   r\   theRestr   r   s           r3   rf   zCodeBlockProcessor.run  sI   ..((

1GK5$8$8w<< %9#AJNf44 1:D!ZZ..NE7)!!$)T-=ellnn-M-MNN DII
 "6511C#C00D!ZZ..NE7)&43CELLNN3S3S*STTDI 	& MM!W%%%%%		& 	&r5   Nrh   r   ri   rj   rk   rl   ra   rf   r_   r5   r3   r)   r)      sB          5 5 5 5& & & & & &r5   r)   c                  J    e Zd ZdZ ej        d          Zdd	ZddZddZ	dS )r/   z Process blockquotes. z(^|\n)[ ]{0,3}>[ ]?(.*)r=   r>   r\   rE   r   r]   c                x    t          | j                            |                    ot          j                     S r9   )r]   REsearchr   nearing_recursion_limitr`   s      r3   ra   zBlockQuoteProcessor.test!  s/    DGNN5))**Q43O3Q3Q/QQr5   rb   rc   r   c                    |                     d          } j                            |          }|r|d |                                         } j                            ||g           d                     fd||                                d                              d          D                       }                     |          }||j	        dk    r|}nt          j        |d          } j        j                            d            j                            ||            j        j                                         d S )Nr   rJ   c                :    g | ]}                     |          S r_   )clean).0rT   r;   s     r3   
<listcomp>z+BlockQuoteProcessor.run.<locals>.<listcomp>-  s%    LLLdD!!LLLr5   
blockquote)r   r   r   startr2   r   rQ   rM   rC   r|   r   r   rz   r   r   r   )r;   r=   rb   r\   r   beforer   r   s   `       r3   rf   zBlockQuoteProcessor.run$  s6   

1GNN5!! 	:AGGII:&FK##FVH555IILLLLeAGGIIJJ.?.E.Ed.K.KLLL E ..((7;,#>#>EE $V\::E 	l+++ue,,,!!!!!r5   rT   c                    | j                             |          }|                                dk    rdS |r|                    d          S |S )z& Remove `>` from beginning of a line. >rL      )r   r   rP   r   )r;   rT   r   s      r3   r   zBlockQuoteProcessor.clean<  sJ    GMM$::<<32 	771::Kr5   Nrh   r   )rT   rE   r   rE   )
ri   rj   rk   rl   rs   rt   r   ra   rf   r   r_   r5   r3   r/   r/     sl          	.	/	/BR R R R" " " "0     r5   r/   c                       e Zd ZU dZdZded<   	 dZded<   	 dZded	<   	 dd
gZded<   	 d fdZ	ddZ
ddZddZ xZS )r-   z Process ordered list blocks. rp   rE   TAG1
STARTSWITHTr]   LAZY_OLro   rc   SIBLING_TAGSr2   r   c                6   t                                          |           t          j        d| j        dz
  z            | _        t          j        d| j        dz
  z            | _        t          j        d| j        | j        dz  dz
  fz            | _        d S )Nz^[ ]{0,%d}\d+\.[ ]+(.*)r   z!^[ ]{0,%d}((\d+\.)|[*+-])[ ]+(.*)z ^[ ]{%d,%d}((\d+\.)|[*+-])[ ]+.*r   )rr   r<   rs   rt   r:   r   CHILD_REru   r;   r2   rw   s     r3   r<   zOListProcessor.__init__Y  s       *74?Q;NOPP
#G$(Oa$7$9 : : $G%)_do6IA6M$N%O P Pr5   r=   r>   r\   r   c                P    t          | j                            |                    S r9   r]   r   r   r`   s      r3   ra   zOListProcessor.testd      DGMM%(()))r5   rb   r   c                $   |                      |                    d                    }|                     |          }|U|j        | j        v rF|}|d         j        rOt          j        d          }|d         j        |_        d|d         _        |d                             d|           |                     |d                   }|G|j	        r@t          j
        |d         d          }|j	                                        |_        d|_	        t          j
        |d          }| j        j                            d           |                    d          }	| j                            ||	g           | j        j                                         nG|j        dv r|}n;t          j
        || j                  }| j        s| j        dk    r| j        |j        d	<   | j        j                            d
           |D ]s}
|
                    d| j        z            r#| j                            |d         |
g           Bt          j
        |d          }| j                            ||
g           t| j        j                                         d S )Nr   rA   r   rL   rn   	looselist)rp   ro   r   r   r   rK   )	get_itemsr   rC   r|   r   rD   r   r   r   tailr   lstripr2   rz   r   r   r   r   r   r   attribrN   r:   )r;   r=   rb   itemsr   lstr   lchrn   	firstitemitems              r3   rf   zOListProcessor.rung  s_   vzz!}}--..((7;$2C#C#CC 2w| % M#&&R!BBq!$$$ ..R))C38$SWc22** !#t,,BK!!+...		!IK##B444K##%%%%Z<'' CC "64844C< 6DOs$:$:&*o
7#f%%%  	4 	4Ds4?233 4''B$8888 %c400''TF3333!!!!!r5   c                   g }|                     d          D ]<}| j                            |          }|r|s^| j        dk    rSt	          j        d          }|                    |                    d                                                    | _        |                    |                    d                     | j	                            |          r[|d         
                    d| j        z            r!d                    |d         |          |d<   |                    |           d                    |d         |          |d<   >|S )	z  Break a block into list items. rJ   rp   z(\d+)r      rA   rK   {}
{})rM   r   r   r   rs   rt   r   r   rO   ru   rN   r:   r   )r;   r\   r   rT   r   
INTEGER_REs         r3   r   zOListProcessor.get_items  s>   KK%% 	= 	=D##D))A =  KT!1!1!#H!5!5J&0&6&6qwwqzz&B&B&H&H&J&JDOQWWQZZ((((%%d++ 	=9''DO(;<< ' (b	4 @ @E"IILL&&&& %OOE"It<<b		r5   rg   rh   r   )r\   rE   r   rc   )ri   rj   rk   rl   r   __annotations__r   r   r   r<   ra   rf   r   r   r   s   @r3   r-   r-   G  s         ((COOOO6J G*#TlL****
	P 	P 	P 	P 	P 	P* * * *9" 9" 9" 9"v       r5   r-   c                  6     e Zd ZU dZdZded<   	 d fdZ xZS )	r.   z  Process unordered list blocks. ro   rE   r   r2   r   c                    t                                          |           t          j        d| j        dz
  z            | _        d S )Nz^[ ]{0,%d}[*+-][ ]+(.*)r   )rr   r<   rs   rt   r:   r   r   s     r3   r<   zUListProcessor.__init__  s=       *74?Q;NOPPr5   rg   )ri   rj   rk   rl   r   r   r<   r   r   s   @r3   r.   r.     s_         **COOOO6Q Q Q Q Q Q Q Q Q Qr5   r.   c                  B    e Zd ZdZ ej        d          Zdd	ZddZdS )r*   z Process Hash Headers. z>(?:^|\n)(?P<level>#{1,6})(?P<header>(?:\\.|[^\\])*?)#*(?:\n|$)r=   r>   r\   rE   r   r]   c                P    t          | j                            |                    S r9   )r]   r   r   r`   s      r3   ra   zHashHeaderProcessor.test  s    DGNN5))***r5   rb   rc   r   c           	        |                     d          }| j                            |          }|r
|d |                                         }||                                d          }|r| j                            ||g           t          j        |dt          |
                    d                    z            }|
                    d                                          |_        |rL| j        j                            d          r|                     |          }|                    d|           d S d S t"                              d|z             d S )Nr   h%drV   headerr   zWe've got a problem header: %r)r   r   r   r   endr2   r   r   r   rB   r   rP   rD   rz   r{   r[   r   loggerwarn)r;   r=   rb   r\   r   r   afterhs           r3   rf   zHashHeaderProcessor.run  s@   

1GNN5!! 	B:AGGII:&F!%%''((OE : ''999 QWWW5E5E1F1F)FGGAWWX&&,,..AF (;$,,[99 3 !OOE22Ea'''''( ( KK85@AAAAAr5   Nrh   r   )	ri   rj   rk   rl   rs   rt   r   ra   rf   r_   r5   r3   r*   r*     s\        !! 
U	V	VB+ + + +B B B B B Br5   r*   c                  N    e Zd ZdZ ej        dej                  Zdd	ZddZ	dS )r+   z Process Setext-style Headers. z^.*?\n[=-]+[ ]*(\n|$)r=   r>   r\   rE   r   r]   c                P    t          | j                            |                    S r9   r   r`   s      r3   ra   zSetextHeaderProcessor.test  r   r5   rb   rc   r   c                   |                     d                              d          }|d                             d          rd}nd}t          j        |d|z            }|d                                         |_        t          |          dk    r3|                    dd	                    |dd                               d S d S )Nr   rJ   r   =r   r   )
r   rM   rN   r   r   rP   rD   rB   r   rQ   )r;   r=   rb   rS   rV   r   s         r3   rf   zSetextHeaderProcessor.run  s    

1##D))8s## 	EEEVUU]33q!!u::>>MM!TYYuQRRy1122222 >r5   Nrh   r   
ri   rj   rk   rl   rs   rt   	MULTILINEr   ra   rf   r_   r5   r3   r+   r+     sZ        )) 
,bl	;	;B* * * *3 3 3 3 3 3r5   r+   c                  R    e Zd ZdZdZ ej        eej                  Zdd	Z	ddZ
dS )r,   z Process Horizontal Rules. zf^[ ]{0,3}(?=(?P<atomicgroup>(-+[ ]{0,2}){3,}|(_+[ ]{0,2}){3,}|(\*+[ ]{0,2}){3,}))(?P=atomicgroup)[ ]*$r=   r>   r\   rE   r   r]   c                P    | j                             |          }|r	|| _        dS dS )NTF)	SEARCH_REr   r   )r;   r=   r\   r   s       r3   ra   zHRProcessor.test  s0    N!!%(( 	DJ4ur5   rb   rc   r   c                   |                     d          }| j        }|d |                                                             d          }|r| j                            ||g           t          j        |d           ||                                d          	                    d          }|r|
                    d|           d S d S )Nr   rJ   r   )r   r   r   r   r2   r   r   r   r   r   r   )r;   r=   rb   r\   r   prelines	postliness          r3   rf   zHRProcessor.run  s    

1
%++--(//55 	8K##FXJ777&&&%))++,,'..t44	 	(MM!Y'''''	( 	(r5   Nrh   r   )ri   rj   rk   rl   r   rs   rt   r   r   ra   rf   r_   r5   r3   r,   r,     s_        %% 
sB
2r|,,I   ( ( ( ( ( (r5   r,   c                  "    e Zd ZdZddZddZdS )r'   z< Process blocks that are empty or start with an empty line. r=   r>   r\   rE   r   r]   c                2    | p|                     d          S )NrJ   )rN   r`   s      r3   ra   zEmptyBlockProcessor.test)  s    y2E,,T222r5   rb   rc   r   c                   |                     d          }d}|r$d}|dd          }|r|                    d|           |                     |          }|k|j        dk    rbt	          |          rU|d         j        dk    rFt          j        d                    |d         j        |                    |d         _        d S d S d S d S d S )Nr   z

rJ   r   r   r   z{}{})	r   r   rC   r|   rB   r   r   r   rD   )r;   r=   rb   r\   fillerr   r   s          r3   rf   zEmptyBlockProcessor.run,  s    

1 	* FABBiG *a)))..((GK5$8$8w<< %9#AJNf44"/gajov66 GAJOOO  $8$8$8$844r5   Nrh   r   r   r_   r5   r3   r'   r'   &  sB        FF3 3 3 3     r5   r'   c                  N    e Zd ZdZ ej        dej                  Zdd	ZddZ	dS )r0   z Process link references. z\^[ ]{0,3}\[([^\[\]]*)\]:[ ]*\n?[ ]*([^\s]+)[ ]*(?:\n[ ]*)?((["\'])(.*)\4[ ]*|\((.*)\)[ ]*)?$r=   r>   r\   rE   r   r]   c                    dS NTr_   r`   s      r3   ra   zReferenceProcessor.testG      tr5   rb   rc   c                   |                     d          }| j                            |          }|r|                    d                                                                          }|                    d                              d                              d          }|                    d          p|                    d          }||f| j        j	        j
        |<   ||                                d                                          rC|                    d||                                d                              d                     |d |                                                                         rC|                    d|d |                                                             d                     d	S |                    d|           d
S )Nr   r   r   <r         rJ   TF)r   r   r   r   rP   lowerr   r   r2   r   
referencesr   r   r   )r;   r=   rb   r\   r   idlinktitles           r3   rf   zReferenceProcessor.runJ  s~   

1GNN5!! 	!!##))++B771::$$S))0055DGGAJJ,!''!**E-15MDKN%b)QUUWWXX$$&& ?aquuwwxx!7!7!=!=>>>ZaggiiZ &&(( Aaz		z!2!9!9$!?!?@@@4aur5   Nrh   )r=   r>   rb   rc   r   r]   r   r_   r5   r3   r0   r0   A  s^        $$	gikiu
 
B        r5   r0   c                  "    e Zd ZdZddZddZdS )r1   z Process Paragraph blocks. r=   r>   r\   rE   r   r]   c                    dS r   r_   r`   s      r3   ra   zParagraphProcessor.testa  r   r5   rb   rc   r   c                   |                     d          }|                                r| j        j                            d          r|                     |          }|5|j        r"d                    |j        |          |_        d S d|z  |_        d S |j        r"d                    |j        |          |_        d S |	                                |_        d S t          j        |d          }|	                                |_        d S d S )Nr   r   r   z
%sr   )r   rP   r2   rz   r{   rC   r   r   rD   r   r   r   )r;   r=   rb   r\   r   r   s         r3   rf   zParagraphProcessor.rund  s    

1;;== 	({ ((00 ( ..00&| 6'/w|U'K'K'-~ { 5&.oofk5&I&I&+llnn $VS117	( 	(r5   Nrh   r   r   r_   r5   r3   r1   r1   ^  sB        %%   ( ( ( ( ( (r5   r1   )r   r	   r   r   r   r   ) rl   
__future__r   loggingrs   xml.etree.ElementTreer   ElementTreetypingr   r   rL   r   blockparserr   markdownr	   	getLoggerr   r4   r7   r(   r)   r/   r-   r.   r*   r+   r,   r'   r0   r1   r_   r5   r3   <module>r     s  (  # " " " " "  				 % % % % % % % % % % % % % % % % %       $ $ $ $ $ $ "!!!!!!		:	&	&   "[ [ [ [ [ [ [ [|_ _ _ _ _. _ _ _D& & & & & & & &B( ( ( ( (. ( ( (Vs s s s s^ s s sl	Q 	Q 	Q 	Q 	Q^ 	Q 	Q 	Q!B !B !B !B !B. !B !B !BH3 3 3 3 3N 3 3 3.( ( ( ( (. ( ( (D    .   6       :#( #( #( #( #( #( #( #( #( #(r5   