o
    g|                     @  s   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
Z
er(ddlmZ dddZG dd de	jZG dd deZG dd deZe	dG dd deZdS )a5  

Post-processors run on the text of the entire document after is has been serialized into a string.
Postprocessors should be used to work with the text just before output. Usually, they are used add
back sections that were extracted in a preprocessor, fix up outgoing encodings, or wrap the whole
document.

    )annotations)OrderedDict)TYPE_CHECKINGAny   )utilN)Markdownmdr   kwargsr   returnutil.Registry[Postprocessor]c                 K  s.   t  }|t| dd |t dd |S )z0 Build the default postprocessors for Markdown. raw_html   amp_substitute   )r   RegistryregisterRawHtmlPostprocessorAndSubstitutePostprocessor)r	   r
   postprocessors r   W/var/www/html/bloggers_ems/venv/lib/python3.10/site-packages/markdown/postprocessors.pybuild_postprocessors(   s   r   c                   @  s   e Zd ZdZdddZdS )	Postprocessora  
    Postprocessors are run after the ElementTree it converted back into text.

    Each Postprocessor implements a `run` method that takes a pointer to a
    text string, modifies it as necessary and returns a text string.

    Postprocessors must extend `Postprocessor`.

    textstrr   c                 C  s   dS )z
        Subclasses of `Postprocessor` should implement a `run` method, which
        takes the html document as a single text string and returns a
        (possibly modified) string.

        Nr   selfr   r   r   r   run;   s   zPostprocessor.runNr   r   r   r   __name__
__module____qualname____doc__r   r   r   r   r   r   0   s    
r   c                   @  s8   e Zd ZdZedZdddZdd
dZdddZ	dS )r   z# Restore raw html to the document. z^\<\/?([^ >]+)r   r   c                   s   t   t| jjjD ]&}| | jjj| }| |r'| d| jj	|< | | jj	|< q
 fdd} rPt
jd }td| d| }|||}n|S ||krX|S | |S )z+ Iterate over html stash and restore html. z	<p>{}</p>c                   sF   |  d}| vr|dd  v rd |dd   dS |S  | S )Nr      <p>z</p>)group)mkeyreplacementsr   r   substitute_matchT   s   
z2RawHtmlPostprocessor.run.<locals>.substitute_matchz([0-9]+)r'   z</p>|)r   ranger	   	htmlStashhtml_counterstash_to_stringrawHtmlBlocksisblocklevelformatget_placeholderr   HTML_PLACEHOLDERrecompilesubr   )r   r   ihtmlr-   base_placeholderpatternprocessed_textr   r+   r   r   J   s$   


zRawHtmlPostprocessor.runr;   r   boolc                 C  s<   | j |}|r|dd dv rdS | j|dS dS )z( Check is block of HTML is block-level. r   r   )!?@%TF)BLOCK_LEVEL_REGEXmatchr(   r	   is_block_level)r   r;   r)   r   r   r   r3   k   s   z!RawHtmlPostprocessor.isblocklevelc                 C  s   t |S )z' Convert a stashed object to a string. )r   r   r   r   r   r1   u   s   z$RawHtmlPostprocessor.stash_to_stringN)r   r   )r;   r   r   r?   r   )
r!   r"   r#   r$   r7   r8   rD   r   r3   r1   r   r   r   r   r   E   s    


!
r   c                   @  s   e Zd ZdZdd ZdS )r   z Restore valid entities c                 C  s   | tjd}|S )N&)replacer   AMP_SUBSTITUTEr   r   r   r   r   }   s   zAndSubstitutePostprocessor.runNr    r   r   r   r   r   z   s    r   zThis class is deprecated and will be removed in the future; use [`UnescapeTreeprocessor`][markdown.treeprocessors.UnescapeTreeprocessor] instead.c                   @  s6   e Zd ZdZedejej	Z
dd Zdd ZdS )UnescapePostprocessorz Restore escaped chars. z	{}(\d+){}c                 C  s   t t|dS )Nr   )chrintr(   )r   r)   r   r   r   unescape   s   zUnescapePostprocessor.unescapec                 C  s   | j | j|S )N)REr9   rM   r   r   r   r   r      s   zUnescapePostprocessor.runN)r!   r"   r#   r$   r7   r8   r4   r   STXETXrN   rM   r   r   r   r   r   rJ      s
    rJ   )r	   r   r
   r   r   r   )r$   
__future__r   collectionsr   typingr   r    r   r7   markdownr   r   	Processorr   r   r   
deprecatedrJ   r   r   r   r   <module>   s    	
5