
    PhZ                     x   d dl Z d dlmZmZmZmZmZmZmZm	Z	 ddl
mZ erddlmZ ddlmZmZ ddlmZ g dZd	Zd
Z e j,                  d      Z e j,                  dez   dz         Z e j,                  d      Z e j,                  d      Z e j,                  d      Zdddee   dddee   fdZdddee   dddee   fdZdedede	ed   eeeef   ee   f   f   fdZ dedee   deeeef      fdZ!d d!dedefd"Z"d d!dedefd#Z#d d!dedefd$Z$d d!dedefd%Z%d+d d!dedee   d&e&def
d'Z'd,d(Z(d,d)Z)d,d*Z*y)-    N)TYPE_CHECKINGAnyDictListMatchOptionalTupleUnion   )PREVENT_BACKSLASH)BlockParser)BaseRenderer
BlockState)Markdown)tabletable_in_quotetable_in_listz^ {0,3}\|(?P<table_head>.+)\|[ \t]*\n {0,3}\|(?P<table_align> *[-:]+[-| :]*)\|[ \t]*\n(?P<table_body>(?: {0,3}\|.*\|[ \t]*(?:\n|$))*)\n*zv^ {0,3}(?P<nptable_head>\S.*\|.*)\n {0,3}(?P<nptable_align>[-:]+ *\|[-| :]*)\n(?P<nptable_body>(?:.*\|.*(?:\n|$))*)\n*z^ {0,3}\|(.+)\|[ \t]*$z *z\| *z
^ *:-+: *$z	^ *:-+ *$z	^ *-+: *$blockr   mstater   returnc                    |j                         }|j                  d      }|j                  d      }t        ||      \  }}|sy |J g }|j                  d      }	|	j                         D ]K  }
t        j                  |
      }|s y t        |j                  d      |      }|s y |j                  |       M |d|dg}|j                  d|d       |S )N
table_headtable_align
table_body   typechildrenr   )	endgroup_process_thead
splitlines
TABLE_CELLmatch_process_rowappendappend_token)r   r   r   posheaderaligntheadalignsrowsbodytextm2rowr   s                 O/var/www/html/saasai/venv/lib/python3.12/site-packages/mistune/plugins/table.pyparse_tabler4   +   s    
%%'CWW\"FGGM"E"651ME6D77< D!d#288A;/C " $?@H	X>?J    c                 Z   |j                  d      }|j                  d      }t        ||      \  }}|sy |J g }|j                  d      }|j                         D ]#  }	t        |	|      }
|
s y |j	                  |
       % |d|dg}|j                  d|d       |j                         S )Nnptable_headnptable_alignnptable_bodyr   r   r   )r!   r"   r#   r&   r'   r(   r    )r   r   r   r*   r+   r,   r-   r.   r/   r0   r2   r   s               r3   parse_nptabler:   D   s    WW^$FGGO$E"651ME6D77>"D!4(C	 " $?@H	X>?557Nr5   r*   r+   NNc           	         t         j                  |       }t         j                  |      }t        |      t        |      k7  ryt        |      D ][  \  }}t        j                  |      rd||<   !t        j                  |      rd||<   <t        j                  |      rd||<   Wd ||<   ] t        |      D cg c]  \  }}d|j                         ||   ddd! }}}d	|d
}||fS c c}}w )Nr;   centerleftright
table_cellTr+   headr   r0   attrsr   r   )	
CELL_SPLITsplitlen	enumerateALIGN_CENTERr%   
ALIGN_LEFTALIGN_RIGHTstrip)	r*   r+   headersr-   ivr0   r   r,   s	            r3   r"   r"   Y   s    v&Ge$F
7|s6{"&!1a  F1Ia F1Iq!F1IF1I " !))GAt tzz|q	[_>`a)   "x8E&=s   :$C*r0   r-   c           	          t         j                  |       }t        |      t        |      k7  ry t        |      D  cg c]  \  }} d| j	                         ||   ddd! }}} d|dS c c} }w )Nr@   FrA   rC   	table_rowr   )rE   rF   rG   rH   rL   )r0   r-   cellsrN   r   s        r3   r&   r&   q   sy    T"E
5zS[  !''GAt tzz|q	[`>ab'    X66	s   $A(rendererr   c                     d|z   dz   S )Nz<table>
z	</table>
 rS   r0   s     r3   render_tablerW   }       ,,r5   c                     d|z   dz   S )Nz<thead>
<tr>
z</tr>
</thead>
rU   rV   s     r3   render_table_headrZ      s    t#&999r5   c                     d|z   dz   S )Nz<tbody>
z	</tbody>
rU   rV   s     r3   render_table_bodyr\      rX   r5   c                     d|z   dz   S )Nz<tr>
z</tr>
rU   rV   s     r3   render_table_rowr^      s    d?Y&&r5   rB   c                 V    |rd}nd}d|z   }|r|d|z   dz   z  }|dz   |z   dz   |z   dz   S )	Nthtdz  <z style="text-align:">z</z>
rU   )rS   r0   r+   rB   taghtmls         r3   render_table_cellrf      sN    3;D%-33#:t#c)E11r5   c                 .   | j                   j                  dt        t        d       | j                   j                  dt        t
        d       | j                  r| j                  j                  dk(  r| j                  j                  dt               | j                  j                  dt               | j                  j                  dt               | j                  j                  dt               | j                  j                  d	t               y
y
y
)a]  A mistune plugin to support table, spec defined at
    https://michelf.ca/projects/php-markdown/extra/#table

    Here is an example:

    .. code-block:: text

        First Header  | Second Header
        ------------- | -------------
        Content Cell  | Content Cell
        Content Cell  | Content Cell

    :param md: Markdown instance
    r   	paragraphbeforenptablere   r   r   rQ   r@   N)r   registerTABLE_PATTERNr4   NP_TABLE_PATTERNr:   rS   NAMErW   rZ   r\   r^   rf   mds    r3   r   r      s     HHg}k+NHHi!1=U	{{r{{''61
Wl3
\+<=
\+<=
[*:;
\+<= 2{r5   c                     | j                   j                  | j                   j                  dd       | j                   j                  | j                   j                  dd       y)z$Enable table plugin in block quotes.r   rh   ri   rk   N)r   insert_ruleblock_quote_rulesrp   s    r3   r   r      sH    HH33W[QHH33Y{Sr5   c                     | j                   j                  | j                   j                  dd       | j                   j                  | j                   j                  dd       y)zEnable table plugin in list.r   rh   ri   rk   N)r   rs   
list_rulesrp   s    r3   r   r      sH    HH,,gkJHH,,iLr5   )NF)rq   r   r   N)+retypingr   r   r   r   r   r   r	   r
   helpersr   block_parserr   corer   r   markdownr   __all__rm   rn   compiler$   rE   rI   rJ   rK   strintr4   r:   r"   r&   rW   rZ   r\   r^   boolrf   r   r   r   rU   r5   r3   <module>r      s   		 	 	 (*/# 7: 0  RZZ12
RZZ 11G;<
rzz-(RZZ%
bjj&} s L XVY] 2 5: l xX[} *3 s uU:5FdSVX[S[n^bcf^gNgHh5h/i 0	7s 	7DI 	7(4S>2J 	7-> - - -: :c :c :- -c -c -'~ 'S 'S '
2 
2c 
2(3- 
2^b 
2or 
2>4TMr5   