o
    .d                     @   sZ   d Z ddlmZ ddlmZ ddlmZ ddlmZ G dd deZded	efd
dZ	dS )z+Utilities for working with strings of HTML.    )
HTMLParser)List)Optional)Tuplec                       s   e Zd ZdZd fddZdedeeeee f  ddf fdd	Z	deddf fd
dZ
deddfddZdeddfddZdeddfddZdefddZ  ZS )StripParserz$An HTML parser that strips out tags.returnNc                    s,   t  jdd |   d| _d| _g | _d S )NF)convert_charrefsr   )super__init__resetscript_depthstyle_depthdatself	__class__ I/var/www/Matress/matenv/lib/python3.10/site-packages/liquid/utils/html.pyr
      s
   
zStripParser.__init__tagattrsc                    s<   |dkr|  j d7  _ n|dkr|  jd7  _t ||S Nscript   style)r   r   r	   handle_starttag)r   r   r   r   r   r   r      s
   zStripParser.handle_starttagc                    s:   |dkr|  j d8  _ n|dkr|  jd8  _t |S r   )r   r   r	   handle_endtag)r   r   r   r   r   r      s
   zStripParser.handle_endtagdatac                 C   s$   | j s| js| j| d S d S d S )Nr   r   r   append)r   r   r   r   r   handle_data#   s   zStripParser.handle_datanamec                 C   ,   | j s| js| jd| d d S d S d S )N&;r   r   r!   r   r   r   handle_entityref'      zStripParser.handle_entityrefc                 C   r"   )Nz&#r$   r   r%   r   r   r   handle_charref+   r'   zStripParser.handle_charrefc                 C   s   d | jS )zReturn accumulated data. )joinr   r   r   r   r   get_data/   s   zStripParser.get_data)r   N)__name__
__module____qualname____doc__r
   strr   r   r   r   r   r    r&   r(   r+   __classcell__r   r   r   r   r      s    *r   valuer   c                 C   s4   d| v rd| v rt  }||  |  | S | S )z2Return the given value with all HTML tags removed.<>)r   feedcloser+   )r2   parserr   r   r   
strip_tags4   s   
r8   N)
r/   html.parserr   typingr   r   r   r   r0   r8   r   r   r   r   <module>   s    )