
    Mh                        d dl mZ d dlmc mZ d dlmZ d dlmZ ddl	m
Z
mZ dgZ G d d          Z G d	 d
e          ZddZ e            ZdS )    )annotationsN)	Formatter)Any   )FormattedTextStyleAndTextTuplesHTMLc                  :    e Zd ZdZddZddZdd	ZddZddZdS )r	   a  
    HTML formatted text.
    Take something HTML-like, for use as a formatted string.

    ::

        # Turn something into red.
        HTML('<style fg="ansired" bg="#00ff44">...</style>')

        # Italic, bold, underline and strike.
        HTML('<i>...</i>')
        HTML('<b>...</b>')
        HTML('<u>...</u>')
        HTML('<s>...</s>')

    All HTML elements become available as a "class" in the style sheet.
    E.g. ``<username>...</username>`` can be styled, by setting a style for
    ``username``.
    valuestrreturnNonec                    || _         t          j        d| d          }g g g g d
fddfd	 |           t                    | _        d S )Nz<html-root>z</html-root>r   r   c                    g } r+|                      dd                              z              r|                      dd         z              r|                      dd         z              d                    |           S )z$Build style string for current node.zclass:,zfg:zbg: )appendjoin)partsbg_stackfg_stack
name_stacks    b/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/formatted_text/html.pyget_current_stylez(HTML.__init__.<locals>.get_current_style*   s    E >X(<(<<=== 3UXb\1222 3UXb\122288E??"    noder   r   c                   | j         D ]9}|j        |j        k    r%                     	            |j        f           8|j        dv}dx}}|j                                        D ]\  }}|dk    r|}|dk    r|}|dk    r|}d|v rt          d          d|v rt          d          |r
                    |j                   |r                    |           |r                    |            |           |r
	                                 |r	                                 |r	                                 ;d	S )
zProcess node recursively.)z	#documentz	html-rootstyle fgbgcolorr   z "fg" attribute contains a space.z "bg" attribute contains a space.N)

childNodesnodeType	TEXT_NODEr   datanodeName
attributesitems
ValueErrorpop)r   childadd_to_name_stackr!   r"   kvr   r   r   r   process_noderesults          r   r1   z#HTML.__init__.<locals>.process_node6   s    (' ('>U_44MM#4#4#6#6
"CDDDD(- ? )%
 !LB % 0 6 6 8 8 # #199!"B99!"B<<!"B byy()KLLLbyy()KLLL( :"))%.999 , +++ , +++ L'''( )"((( '  ' Q(' ('r   r   r   )r   r   r   r   )r   minidomparseStringr   formatted_text)	selfr   documentr   r   r   r   r1   r2   s	      @@@@@@r   __init__zHTML.__init__!   s    
&'HU'H'H'HII%' "
  
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	#*	' *	' *	' *	' *	' *	' *	' *	' *	' *	' *	'X 	X+F33r   c                    d| j         dS )NzHTML())r   r7   s    r   __repr__zHTML.__repr__f   s    &tz&&&&r   r   c                    | j         S N)r6   r<   s    r   __pt_formatted_text__zHTML.__pt_formatted_text__i   s    ""r   argsobjectkwargsc                ^    t          t                              | j        ||                    S )zc
        Like `str.format`, but make sure that the arguments are properly
        escaped.
        )r	   	FORMATTERvformatr   )r7   rA   rC   s      r   formatzHTML.formatl   s&    
 I%%dj$??@@@r   c                    t          |t                    s|f}t          d |D                       }t          | j        |z            S )z+
        HTML('<b>%s</b>') % value
        c              3  4   K   | ]}t          |          V  d S r?   )html_escape).0is     r   	<genexpr>zHTML.__mod__.<locals>.<genexpr>z   s(      44k!nn444444r   )
isinstancetupler	   r   )r7   r   s     r   __mod__zHTML.__mod__s   sN     %'' 	HE44e44444DJ&'''r   N)r   r   r   r   r3   )r   r   )rA   rB   rC   rB   r   r	   )r   rB   r   r	   )	__name__
__module____qualname____doc__r9   r=   r@   rG   rP    r   r   r	   r	      s         (C4 C4 C4 C4J' ' ' '# # # #A A A A( ( ( ( ( (r   c                      e Zd ZddZdS )	HTMLFormatterr   rB   format_specr   r   c                <    t          t          ||                    S r?   )rJ   rG   )r7   r   rX   s      r   format_fieldzHTMLFormatter.format_field   s    6%55666r   N)r   rB   rX   r   r   r   )rQ   rR   rS   rZ   rU   r   r   rW   rW   ~   s(        7 7 7 7 7 7r   rW   textrB   r   r   c                    t          | t                    s|  } |                     dd                              dd                              dd                              dd          S )	N&z&amp;<z&lt;>z&gt;"z&quot;)rN   r   replace)r[   s    r   rJ   rJ      sb     dC   y 	S'""	f			f			h			r   )r[   rB   r   r   )
__future__r   xml.dom.minidomdomr4   stringr   typingr   baser   r   __all__r	   rW   rJ   rE   rU   r   r   <module>ri      s    " " " " " " ! ! ! ! ! ! ! ! !             3 3 3 3 3 3 3 3(o( o( o( o( o( o( o( o(d7 7 7 7 7I 7 7 7
    MOO			r   