o
    +e                     @  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. Zraw_html   Zamp_substitute   )r   ZRegistryregisterRawHtmlPostprocessorAndSubstitutePostprocessor)r	   r
   Zpostprocessors r   7lib/python3.10/site-packages/markdown/postprocessors.pybuild_postprocessors(   s   r   c                   @     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   r   c                   s   t   t| jjjD ]&}| | jjj| }| |r'| d| jj	|< | | jj	|< q
d fdd} rQt
jd }td	| d
| }|||}n|S ||krY|S | |S )z+ Iterate over html stash and restore html. z	<p>{}</p>mre.Match[str]r   r   c                   sF   |  d}| vr|dd  v rd |dd   dS |S  | S )Nr      <p>z</p>)group)r"   keyZreplacementsr   r   substitute_matchT   s   
z2RawHtmlPostprocessor.run.<locals>.substitute_matchz([0-9]+)r&   z</p>|Nr"   r#   r   r   )r   ranger	   Z	htmlStashZhtml_counterstash_to_stringZrawHtmlBlocksisblocklevelformatZget_placeholderr   ZHTML_PLACEHOLDERrecompilesubr   )r   r   ihtmlr*   Zbase_placeholderpatternZprocessed_textr   r)   r   r   J   s$   


zRawHtmlPostprocessor.runr4   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	   Zis_block_level)r   r4   r"   r   r   r   r.   k   s   z!RawHtmlPostprocessor.isblocklevelc                 C  s   t |S )z' Convert a stashed object to a string. )r   r   r   r   r   r-   u   s   z$RawHtmlPostprocessor.stash_to_stringNr   )r4   r   r   r6   )
r   r   r    r!   r0   r1   r;   r   r.   r-   r   r   r   r   r   E   s    


!
r   c                   @  r   )	r   z Restore valid entities r   r   r   c                 C  s   | tjd}|S )N&)replacer   ZAMP_SUBSTITUTEr   r   r   r   r   }   s   zAndSubstitutePostprocessor.runNr   r   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                   @  s:   e Zd ZdZedejej	Z
dddZdd
dZdS )UnescapePostprocessorz Restore escaped chars. z	{}(\d+){}r"   r#   r   r   c                 C  s   t t|dS )Nr   )chrintr'   )r   r"   r   r   r   unescape   s   zUnescapePostprocessor.unescaper   c                 C  s   | j | j|S )N)REr2   rB   r   r   r   r   r      s   zUnescapePostprocessor.runNr+   r   )r   r   r    r!   r0   r1   r/   r   ZSTXZETXrC   rB   r   r   r   r   r   r?      s
    
r?   )r	   r   r
   r   r   r   )r!   Z
__future__r   collectionsr   typingr   r    r   r0   Zmarkdownr   r   Z	Processorr   r   r   Z
deprecatedr?   r   r   r   r   <module>   s    	
5