U
    cc
                     @   s   d dl m  mZ d dlmZ d dlmZmZ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eed
ddZe ZdS )    N)	Formatter)AnyListTupleUnion   )FormattedTextStyleAndTextTuplesHTMLc                   @   s^   e Zd ZdZeddddZedddZedd	d
Ze	e	d dddZ
e	d 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``.
    N)valuereturnc                    sr   || _ td| d}g g g g  td fddtd d fdd| t| _d S )	Nz<html-root>z</html-root>r   c                     sR   g } r|  dd  r2|  dd    rH|  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/html/project/venv/lib/python3.8/site-packages/prompt_toolkit/formatted_text/html.pyget_current_style(   s    z(HTML.__init__.<locals>.get_current_style)noder   c                    s   | j D ]}|j|jkr* |jf q|jdk}d }}|j D ],\}}|dkrZ|}|dkrf|}|dkrF|}qFd|krtdd|krtd|r|j |r| |r | | |rԈ	  |r	  |r 	  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)
Z
childNodesZnodeTypeZ	TEXT_NODEr   dataZnodeName
attributesitems
ValueErrorpop)r   childZadd_to_name_stackr   r   kvr   r   r   r   process_noderesultr   r   r)   4   s:    



z#HTML.__init__.<locals>.process_node)r   minidomparseStringstrr   r   formatted_text)selfr   Zdocumentr   r(   r   __init__   s    ,zHTML.__init__r   c                 C   s   d| j dS )NzHTML())r   r/   r   r   r   __repr__d   s    zHTML.__repr__c                 C   s   | j S N)r.   r2   r   r   r   __pt_formatted_text__g   s    zHTML.__pt_formatted_text__)argskwargsr   c                 O   s   t t| j||S )zc
        Like `str.format`, but make sure that the arguments are properly
        escaped.
        )r
   	FORMATTERvformatr   )r/   r6   r7   r   r   r   formatj   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 r4   )html_escape).0ir   r   r   	<genexpr>x   s     zHTML.__mod__.<locals>.<genexpr>)
isinstancetupler
   r   )r/   r   r   r   r   __mod__q   s    
zHTML.__mod__)__name__
__module____qualname____doc__r-   r0   r3   r	   r5   objectr:   rA   r   r   r   r   r
   
   s   Ec                   @   s   e Zd ZeeedddZdS )HTMLFormatter)r   format_specr   c                 C   s   t t||S r4   )r;   r:   )r/   r   rH   r   r   r   format_field}   s    zHTMLFormatter.format_fieldN)rB   rC   rD   rF   r-   rI   r   r   r   r   rG   |   s   rG   )textr   c                 C   s4   t | ts|  } | ddddddddS )	N&z&amp;<z&lt;>z&gt;"z&quot;)r?   r-   replace)rJ   r   r   r   r;      s    
   r;   )Zxml.dom.minidomdomr+   stringr   typingr   r   r   r   baser   r	   __all__r
   rG   rF   r-   r;   r8   r   r   r   r   <module>   s   r