U
    muf~                     @   s   d dl Z ddlmZ dddg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||\}}|s2d S g }|d}	|	 D ]<}
t|
}|s` d S t|d|}|sz d S || qH|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"   9/tmp/pip-unpacked-wheel-8p1ovdot/mistune/plugins/table.pyparse_table   s&    



r$   c                 C   s   | d}| d}t||\}}|s*d S g }| d}| D ]"}	t|	|}
|
sX 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 ]L\}}t|rLd |< q0t|r`d |< q0t|rtd |< q0d  |< q0 fddt|D }d|d}| fS )	N)NNcenterleftrightc                    s*   g | ]"\}}d |   | dddqS )
table_cellTr   headr   r    attrsstrip.0ir    r   r"   r#   
<listcomp>W   s
   z"_process_thead.<locals>.<listcomp>r   r
   )
CELL_SPLITsplitlen	enumerateALIGN_CENTERr   
ALIGN_LEFTALIGN_RIGHT)r   r   headersr2   vr   r   r"   r3   r#   r   G   s"    










r   c                    s>   t | }t|t krd S  fddt|D }d|dS )Nc                    s*   g | ]"\}}d |   | dddqS )r)   Fr*   r,   r.   r0   r3   r"   r#   r4   h   s
   z _process_row.<locals>.<listcomp>	table_rowr
   )r5   r6   r7   r8   )r    r   cellsr   r"   r3   r#   r   c   s    

r   c                 C   s   d| d S )Nz<table>
z	</table>
r"   rendererr    r"   r"   r#   render_tables   s    rB   c                 C   s   d| d S )Nz<thead>
<tr>
z</tr>
</thead>
r"   r@   r"   r"   r#   render_table_headw   s    rC   c                 C   s   d| d S )Nz<tbody>
z	</tbody>
r"   r@   r"   r"   r#   render_table_body{   s    rD   c                 C   s   d| d S )Nz<tr>
z</tr>
r"   r@   r"   r"   r#   render_table_row   s    rE   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"   )rA   r    r   r+   taghtmlr"   r"   r#   render_table_cell   s    rL   c                 C   s   | j jdttdd | j jdttdd | jr| jjdkr| jdt | jdt	 | jdt
 | jdt | jd	t 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nptablerK   r   r   r>   r)   N)r   registerTABLE_PATTERNr$   NP_TABLE_PATTERNr%   rA   NAMErB   rC   rD   rE   rL   Zmdr"   r"   r#   r      s    c                 C   s0   | j j| j jddd | j j| j jddd dS )z$Enable table plugin in block quotes.r   rM   rN   rP   N)r   insert_ruleZblock_quote_rulesrU   r"   r"   r#   r      s    c                 C   s0   | j j| j jddd | j j| j jddd dS )zEnable table plugin in list.r   rM   rN   rP   N)r   rV   Z
list_rulesrU   r"   r"   r#   r      s    )NF)reZhelpersr   __all__rR   rS   compiler   r5   r9   r:   r;   r$   r%   r   r   rB   rC   rD   rE   rL   r   r   r   r"   r"   r"   r#   <module>   s.   





