o
    i                     @  s   d dl mZ d dlm  mZ d dlmZ d dlmZm	Z	 ddl
mZmZ dgZG dd dZG d	d
 d
eZdddZe ZdS )    )annotationsN)	Formatter)AnyList   )FormattedTextStyleAndTextTuplesHTMLc                   @  sB   e Zd ZdZdddZddd	ZdddZdddZd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                   sh   || _ td| d}g g g g  d fddd fd
d| t| _d S )Nz<html-root>z</html-root>r   r   c                    sR   g } r|  dd  r|  dd    r$|  d d   d| S )z$Build style string for current node.zclass:,zfg:zbg: )appendjoin)parts)bg_stackfg_stack
name_stack ]/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/prompt_toolkit/formatted_text/html.pyget_current_style*   s   
z(HTML.__init__.<locals>.get_current_stylenoder   r   c                   s   | j D ]s}|j|jkr |jf q|jdv}d }}|j D ]\}}|dkr-|}|dkr3|}|dkr9|}q#d|v rBtdd|v rJtd|rR|j |rY| |r` | | |rj	  |rp	  |rv 	  q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vr   r   r   r   process_noderesultr   r   r.   6   s@   



z#HTML.__init__.<locals>.process_noder   r   )r   r   r   r   )r
   minidomparseStringr   formatted_text)selfr
   documentr   r-   r   __init__!   s   ,zHTML.__init__c                 C  s   d| j dS )NzHTML())r
   r4   r   r   r   __repr__f      zHTML.__repr__r   c                 C  s   | j S N)r3   r8   r   r   r   __pt_formatted_text__i   s   zHTML.__pt_formatted_text__argsobjectkwargsc                 O  s   t t| j||S )zc
        Like `str.format`, but make sure that the arguments are properly
        escaped.
        )r	   	FORMATTERvformatr
   )r4   r=   r?   r   r   r   formatl   s   zHTML.formatc                 C  s0   t |ts|f}tdd |D }t| j| S )z+
        HTML('<b>%s</b>') % value
        c                 s  s    | ]}t |V  qd S r;   )html_escape).0ir   r   r   	<genexpr>z   s    zHTML.__mod__.<locals>.<genexpr>)
isinstancetupler	   r
   )r4   r
   r   r   r   __mod__s   s   
zHTML.__mod__N)r
   r   r   r   r0   )r   r   )r=   r>   r?   r>   r   r	   )r
   r>   r   r	   )	__name__
__module____qualname____doc__r6   r9   r<   rB   rI   r   r   r   r   r	      s    

E

c                   @  s   e Zd Zd	ddZdS )
HTMLFormatterr
   r>   format_specr   r   c                 C  s   t t||S r;   )rC   rB   )r4   r
   rO   r   r   r   format_field   r:   zHTMLFormatter.format_fieldN)r
   r>   rO   r   r   r   )rJ   rK   rL   rP   r   r   r   r   rN   ~   s    rN   textr>   r   r   c                 C  s4   t | ts|  } | ddddddddS )	N&z&amp;<z&lt;>z&gt;"z&quot;)rG   r   replace)rQ   r   r   r   rC      s   

rC   )rQ   r>   r   r   )
__future__r   xml.dom.minidomdomr1   stringr   typingr   r   baser   r   __all__r	   rN   rC   r@   r   r   r   r   <module>   s    r

