o
    tf~                     @   s   d dl 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 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd&ddZd d! Zd"d# Zd$d% ZdS )'    N   )PREVENT_BACKSLASH)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	^ *-+: *$c                 C   s   |  }|d}|d}t||\}}|sd S g }|d}	|	 D ]}
t|
}|s0 d S t|d|}|s= d S || q$|d|dg}|d|d |S )N
table_headZtable_align
table_body   typechildrenr   )	endgroup_process_thead
splitlines
TABLE_CELLmatch_process_rowappendappend_token)blockmstateposheaderaligntheadalignsrowsbodytextrowr    r"   ^/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/mistune/plugins/table.pyparse_table   s&   



r$   c                 C   s   | d}| d}t||\}}|sd S g }| d}| D ]}	t|	|}
|
s, d S ||
 q |d|dg}|d|d | S )NZnptable_headZnptable_alignZnptable_bodyr   r
   r   )r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r    r!   r   r"   r"   r#   parse_nptable3   s   



r%   c                    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 )	N)NNcenterleftrightc                    *   g | ]\}}d |   | dddqS )
table_cellTr   headr   r    attrsstrip.0ir    r   r"   r#   
<listcomp>W       z"_process_thead.<locals>.<listcomp>r   r
   )
CELL_SPLITsplitlen	enumerateALIGN_CENTERr   
ALIGN_LEFTALIGN_RIGHT)r   r   headersr3   vr   r   r"   r4   r#   r   G   s"   










r   c                    s>   t | }t|t krd S  fddt|D }d|dS )Nc                    r)   )r*   Fr+   r-   r/   r1   r4   r"   r#   r5   h   r6   z _process_row.<locals>.<listcomp>	table_rowr
   )r7   r8   r9   r:   )r    r   cellsr   r"   r4   r#   r   c   s   


r   c                 C      d| d S )Nz<table>
z	</table>
r"   rendererr    r"   r"   r#   render_tables      rE   c                 C   rB   )Nz<thead>
<tr>
z</tr>
</thead>
r"   rC   r"   r"   r#   render_table_headw   rF   rG   c                 C   rB   )Nz<tbody>
z	</tbody>
r"   rC   r"   r"   r#   render_table_body{   rF   rH   c                 C   rB   )Nz<tr>
z</tr>
r"   rC   r"   r"   r#   render_table_row   rF   rI   Fc                 C   sB   |rd}nd}d| }|r|d| d 7 }|d | d | d S )	Nthtdz  <z style="text-align:">z</z>
r"   )rD   r    r   r,   taghtmlr"   r"   r#   render_table_cell   s   rP   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nptablerO   r   r   r@   r*   N)r   registerTABLE_PATTERNr$   NP_TABLE_PATTERNr%   rD   NAMErE   rG   rH   rI   rP   mdr"   r"   r#   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   rQ   rR   rT   N)r   insert_ruleZblock_quote_rulesrY   r"   r"   r#   r         r   c                 C   r[   )zEnable table plugin in list.r   rQ   rR   rT   N)r   r\   Z
list_rulesrY   r"   r"   r#   r      r]   r   )NF)rehelpersr   __all__rV   rW   compiler   r7   r;   r<   r=   r$   r%   r   r   rE   rG   rH   rI   rP   r   r   r   r"   r"   r"   r#   <module>   s0    




