
    f~                     2   d dl 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 Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Zy)    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                    |j                         }|j                  d      }|j                  d      }t        ||      \  }}|sy 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)blockmstateposheaderaligntheadalignsrowsbodytextrowr   s                P/var/www/cvtools/html/venv/lib/python3.12/site-packages/mistune/plugins/table.pyparse_tabler&      s    
%%'CWW\"FGGM"E"651ME6D77< D! T"1771:v.C $?@H	X>?J    c                 R   |j                  d      }|j                  d      }t        ||      \  }}|sy 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"   r#   r$   r   s               r%   parse_nptabler,   3   s    WW^$FGGO$E"651ME6D77>"D! 4(C	 $?@H	X>?557Nr'   c           	         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 )N)NNcenterleftright
table_cellTr   headr   r#   attrsr	   r   )	
CELL_SPLITsplitlen	enumerateALIGN_CENTERr   
ALIGN_LEFTALIGN_RIGHTstrip)	r   r   headersr    ivr#   r   r   s	            r%   r   r   G   s    v&Ge$F
7|s6{"&! 1a  F1Ia F1Iq!F1IF1I  !) At	 !JJL%ay$7	
H  "x8E&=s   :$C*c           	          t         j                  |       }t        |      t        |      k7  ry t        |      D  cg c]  \  }} d| j	                         ||   ddd! }}} d|dS c c} }w )Nr1   Fr2   r4   	table_rowr   )r6   r7   r8   r9   r=   )r#   r    cellsr?   r   s        r%   r   r   c   s{    T"E
5zS[  !' At	 !JJL%ay%8	
H   X66s   $A(c                     d|z   dz   S )Nz<table>
z	</table>
 rendererr#   s     r%   render_tablerH   s       ,,r'   c                     d|z   dz   S )Nz<thead>
<tr>
z</tr>
</thead>
rE   rF   s     r%   render_table_headrK   w   s    t#&999r'   c                     d|z   dz   S )Nz<tbody>
z	</tbody>
rE   rF   s     r%   render_table_bodyrM   {   rI   r'   c                     d|z   dz   S )Nz<tr>
z</tr>
rE   rF   s     r%   render_table_rowrO      s    d?Y&&r'   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>
rE   )rG   r#   r   r3   taghtmls         r%   render_table_cellrW      sN    3;D%-33#:t#c)E11r'   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nptablerV   r	   r   rB   r1   N)r   registerTABLE_PATTERNr&   NP_TABLE_PATTERNr,   rG   NAMErH   rK   rM   rO   rW   mds    r%   r   r      s     HHg}k+NHHi!1=U	{{r{{''61
Wl3
\+<=
\+<=
[*:;
\+<= 2{r'   c                     | j                   j                  | j                   j                  dd       | j                   j                  | j                   j                  dd       y)z$Enable table plugin in block quotes.r   rY   rZ   r\   N)r   insert_ruleblock_quote_rulesra   s    r%   r   r      sH    HH33W[QHH33Y{Sr'   c                     | j                   j                  | j                   j                  dd       | j                   j                  | j                   j                  dd       y)zEnable table plugin in list.r   rY   rZ   r\   N)r   rd   
list_rulesra   s    r%   r   r      sH    HH,,gkJHH,,iLr'   )NF)rehelpersr   __all__r^   r_   compiler   r6   r:   r;   r<   r&   r,   r   r   rH   rK   rM   rO   rW   r   r   r   rE   r'   r%   <module>rl      s    	 ' 78 .  RZZ12
RZZ 11G;<
rzz-(RZZ%
bjj&0(87 -:-'
2>4TMr'   