o
    ^iZ                     @   s  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r4ddlmZ ddlmZmZ ddlmZ g dZd	Zd
Ze dZe de d Ze dZe dZe dZdddee dddee fddZdddee dddee fddZdedede	ed eeeef ee f f fddZ d ed!ee deeeef  fd"d#Z!d$d%d edefd&d'Z"d$d%d edefd(d)Z#d$d%d edefd*d+Z$d$d%d edefd,d-Z%d:d$d%d edee d/e&def
d0d1Z'd;d4d5Z(d;d6d7Z)d;d8d9Z*dS )<    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                 C   s   |  }|d}|d}t||\}}|sd S |d usJ g }|d}	|	 D ]}
t|
}|s6 d S t|d|}|sC d S || q*|d|dg}|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    r1   P/home/ubuntu/hpml_nyu/venv/lib/python3.10/site-packages/mistune/plugins/table.pyparse_table+   s(   



r3   c                 C   s   | d}| d}t||\}}|sd S |d usJ g }| d}| D ]}	t|	|}
|
s2 d S ||
 q&|d|dg}|d|d | 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-   r.   r0   r   r1   r1   r2   parse_nptableD   s    



r7   r(   r)   NNc                    s   t | }t | t|t krdS t D ]&\}}t|r&d |< qt|r0d |< qt|r:d |< qd  |< q fddt|D }d|d}| fS )	Nr8   centerleftrightc                    *   g | ]\}}d |   | dddqS )
table_cellTr)   headr   r.   attrsstrip.0ir.   r+   r1   r2   
<listcomp>i       z"_process_thead.<locals>.<listcomp>r   r   )
CELL_SPLITsplitlen	enumerateALIGN_CENTERr#   
ALIGN_LEFTALIGN_RIGHT)r(   r)   headersrF   vr   r*   r1   rG   r2   r    Y   s"   










r    r.   r+   c                    s>   t | }t|t krd S  fddt|D }d|dS )Nc                    r<   )r=   Fr>   r@   rB   rD   rG   r1   r2   rH   v   rI   z _process_row.<locals>.<listcomp>	table_rowr   )rJ   rK   rL   rM   )r.   r+   cellsr   r1   rG   r2   r$   q   s   


r$   rendererr   c                 C      d| d S )Nz<table>
z	</table>
r1   rU   r.   r1   r1   r2   render_table}      rX   c                 C   rV   )Nz<thead>
<tr>
z</tr>
</thead>
r1   rW   r1   r1   r2   render_table_head   rY   rZ   c                 C   rV   )Nz<tbody>
z	</tbody>
r1   rW   r1   r1   r2   render_table_body   rY   r[   c                 C   rV   )Nz<tr>
z</tr>
r1   rW   r1   r1   r2   render_table_row   rY   r\   Fr?   c                 C   sB   |rd}nd}d| }|r|d| d 7 }|d | d | d S )	Nthtdz  <z style="text-align:">z</z>
r1   )rU   r.   r)   r?   taghtmlr1   r1   r2   render_table_cell   s   rc   mdr   c                 C   s   | j jdttdd | j jdttdd | jrB| jjdkrD| jdt | jdt	 | jdt
 | jdt | jd	t d
S d
S d
S )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nptablerb   r   r   rS   r=   N)r   registerTABLE_PATTERNr3   NP_TABLE_PATTERNr7   rU   NAMErX   rZ   r[   r\   rc   rd   r1   r1   r2   r      s   r   c                 C   0   | j j| j jddd | j j| j jddd dS )z$Enable table plugin in block quotes.r   re   rf   rh   N)r   insert_ruleblock_quote_rulesrm   r1   r1   r2   r         r   c                 C   rn   )zEnable table plugin in list.r   re   rf   rh   N)r   ro   
list_rulesrm   r1   r1   r2   r      rq   r   )NF)rd   r   r   N)+retypingr   r   r   r   r   r   r   r	   helpersr   block_parserr   corer   r   markdownr   __all__rj   rk   compiler"   rJ   rN   rO   rP   strintr3   r7   r    r$   rX   rZ   r[   r\   boolrc   r   r   r   r1   r1   r1   r2   <module>   s:    (



""6&$

