
    h                        S r SSKJr  SSKrSSKrSSKJr  SSKJr  SSK	J
r
  \(       a  SSKJr  SSKJr  SS	KJr  SS
 jr " S S5      r " S S5      r " S S\5      rg)z*Module for formatting output data in HTML.    )annotationsN)dedent)TYPE_CHECKING)html)Iterable)TracebackType)	DataFramec                4    [         R                  " SS U 5      $ )z9Replace consecutive spaces with HTML non-breaking spaces.z( {2,})c                <    S[        U R                  S5      5      -  $ )Nz&nbsp;r   )lengroup)matchs    P/home/james-whalen/.local/lib/python3.13/site-packages/polars/dataframe/_html.py<lambda>,replace_consecutive_spaces.<locals>.<lambda>   s    Hs5;;q>7J,J    )resub)ss    r   replace_consecutive_spacesr      s    66*JANNr   c                  Z    \ rS rSrSr S       S	S jjrS
S jr        SS jrSrg)Tag   z#Class for representing an HTML tag.Nc                (    X l         Xl        X0l        g N)tagelements
attributes)selfr   r   r   s       r   __init__Tag.__init__   s      $r   c                H   U R                   bl  SU R                   S3nU R                   R                  5        H  u  p#X SU S3-  nM     UR                  5        S3nU R                  R                  U5        g U R                  R                  SU R                   S35        g )N< z="z" >)r   r   itemsrstripr   append)r   r   kvs       r   	__enter__Tag.__enter__%   s    ??&DHH:QA--/s"QCr]" 088:,a AMM  #MM  1TXXJa1r   c                V    U R                   R                  SU R                   S35        g )Nz</r%   )r   r(   r   )r   exc_typeexc_valexc_tbs       r   __exit__Tag.__exit__/   s#     	r$((1-.r   )r   r   r   r   )r   	list[str]r   strr   zdict[str, str] | NonereturnNoner5   r6   )r.   ztype[BaseException] | Noner/   zBaseException | Noner0   zTracebackType | Noner5   r6   )	__name__
__module____qualname____firstlineno____doc__r    r+   r1   __static_attributes__ r   r   r   r      se    - -1	%% % *	%
 
%2/,/ &/ %	/
 
/r   r   c                  d    \ rS rSrSSSS.         SS jjrSS jrSS jrSS	 jrSS
 jrSr	g)HTMLFormatter8   K   (   F)max_colsmax_rowsfrom_seriesc               B   Xl         / U l        X l        X0l        X@l        U   U   X1R
                  :  aZ  [        US5      u  pV/ [        [        XV-   5      5      QSP[        [        UR
                  U-
  UR
                  5      5      QU l	        O[        UR
                  5      U l	        X!R                  :  aP  / [        [        US-  5      5      QSP[        [        UR                  US-  -
  UR                  5      5      QU l        g [        UR                  5      U l        g )N   )dfr   rD   rE   rF   heightdivmodlistrangerow_idxwidthcol_idx)r   rJ   rD   rE   rF   halfrests          r   r    HTMLFormatter.__init__9   s    #%  &ii!,JDeDK() eBII,bii89DL !+DLhheHM*+ eBHHx1}4bhh?@DL !?DLr   c           
        [        U R                  S5         [        [        [        R
                  R                  SS5      5      5      (       d  [        U R                  S5         U R                  R                  nU R                   Hu  n[        U R                  S5         US:X  a  U R                  R                  S5        O1U R                  R                  [        R                  " X   5      5        SSS5        Mw     SSS5        [        [        [        R
                  R                  S	S5      5      5      (       d  [        U R                  S5         U R                  R                  R                  5       nU R                   Ha  n[        U R                  S
5         US:X  a  U R                  R                  S5        OU R                  R                  X2   5        SSS5        Mc     SSS5        SSS5        g! , (       d  f       GM  = f! , (       d  f       GN= f! , (       d  f       M  = f! , (       d  f       NN= f! , (       d  f       g= f)z"Write the header of an HTML table.thead"POLARS_FMT_TABLE_HIDE_COLUMN_NAMES0trthrI   &hellip;N'POLARS_FMT_TABLE_HIDE_COLUMN_DATA_TYPEStd)r   r   boolintosenvirongetrJ   columnsrQ   r(   r   escape_dfdtype_strings)r   rc   cdtypess       r   write_headerHTMLFormatter.write_header[   s   (BJJNN+OQTUVWW-"ggooG!\\ 5 Bw $ 4 4Z @ $ 4 4T[[5L M	 65 * . BJJNN#LcRS  -!WW[[668F!\\ 5 Bw $ 4 4Z @ $ 4 4VY ?	 65 * . )(
 65 .- 65 .- )(sp   AI%<H!AG=	5HAIA
H4 A H"	 H4,I=
H	H
H	I"
H1,H44
I	>I
Ic                   [        [        R                  R                  SSS95      n[	        U R
                  S5         U R                   H  n[	        U R
                  S5         U R                   H  n[	        U R
                  S5         US:X  d  US:X  a  U R
                  R                  S5        OdU R                  S	S	2U4   nU R
                  R                  [        [        R                  " UR                  R                  X!5      5      5      5        S	S	S	5        M     S	S	S	5        M     S	S	S	5        g	! , (       d  f       M  = f! , (       d  f       GM  = f! , (       d  f       g	= f)
z Write the body of an HTML table.POLARS_FMT_STR_LEN   )defaulttbodyrY   r]   rI   r[   N)r_   r`   ra   rb   r   r   rO   rQ   r(   rJ   r   r   rd   _sget_fmt)r   str_len_limitrrg   seriess        r   
write_bodyHTMLFormatter.write_bodys   s    BJJNN+?NLM(\\-!\\ 5 Bw!r' $ 4 4Z @)-A $ 4 4$>(,FII4E4Ea4W(X%&!" 65 * .- " )( 65 .- )(s<   &E$&E

BD8E
#E8
EE


E	E
E+c                :    U R                   R                  U5        g)z&Append a raw string to the inner HTML.N)r   r(   )r   inners     r   writeHTMLFormatter.write   s    U#r   c                   [        [        [        R                  R	                  SS5      5      5      (       da  U R
                  R                  nU R                  (       a
  SUS   S S3OSUS   S SUS   S S	3nU R                  R                  S
U S35        [        U R                  SSSS.5         U R                  5         U R                  5         SSS5        U R                  $ ! , (       d  f       U R                  $ = f)/Return the lines needed to render a HTML table.1POLARS_FMT_TABLE_HIDE_DATAFRAME_SHAPE_INFORMATIONrX   (r   _z,)z,    )z<small>shape: z</small>table1	dataframe)borderclassN)r^   r_   r`   ra   rb   rJ   shaperF   r   r(   r   ri   ru   )r   r   r   s      r   renderHTMLFormatter.render   s    

RTWX
 
 A&*&6&6a!QxrNa!Qxr!A$qQR<SEMM  >%!AB MM[1
 OO
 }}
 
 }}s   3!C((
D)rQ   rJ   r   rF   rD   rE   rO   N)
rJ   r	   rD   r_   rE   r_   rF   r^   r5   r6   r7   )rx   r4   r5   r6   r5   r3   )
r8   r9   r:   r;   r    ri   ru   ry   r   r=   r>   r   r   r@   r@   8   sX    
 ! + + 	 +
  +  + 
 +D@0"$$r   r@   c                  :   ^  \ rS rSrSrSS jrSU 4S jjrSrU =r$ )NotebookFormatter   z
Class for formatting output data in HTML for display in Jupyter Notebooks.

This class is intended for functionality specific to DataFrame._repr_html_().
c                <    SnU R                  [        U5      5        g )Nz            <style>
            .dataframe > thead > tr,
            .dataframe > tbody > tr {
              text-align: right;
              white-space: pre-wrap;
            }
            </style>
        )ry   r   )r   styles     r   write_styleNotebookFormatter.write_style   s     	

6%=!r   c                   > [        U R                  S5         U R                  5         [        TU ]  5         SSS5        U R                  $ ! , (       d  f       U R                  $ = f)r|   divN)r   r   r   superr   )r   	__class__s    r   r   NotebookFormatter.render   sM    &GN ' }} '& }}s   A
A$r>   r7   r   )	r8   r9   r:   r;   r<   r   r   r=   __classcell__)r   s   @r   r   r      s    
" r   r   )r   r4   r5   r4   )r<   
__future__r   r`   r   textwrapr   typingr   polars._dependenciesr   collections.abcr   typesr   polarsr	   r   r   r@   r   r>   r   r   <module>r      sP    0 " 	 	    %(# O
/ /@g gT r   