
    :Qg                        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	Z G d
 de	j                        Z G d de      Z G d de      Z e	j$                  d       G d de             Zy)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)Markdownc                    t        j                         }|j                  t        |       dd       |j                  t	               dd       |S )z0 Build the default postprocessors for Markdown. raw_html   amp_substitute   )r   RegistryregisterRawHtmlPostprocessorAndSubstitutePostprocessor)mdkwargspostprocessorss      T/var/www/html/answerous/venv/lib/python3.12/site-packages/markdown/postprocessors.pybuild_postprocessorsr   (   sB    ]]_N04j"E68:JBO    c                      e Zd ZdZddZy)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`.

    c                     y)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.

        N selftexts     r   runzPostprocessor.run;   s     	r   Nr   strreturnr"   __name__
__module____qualname____doc__r    r   r   r   r   r   0   s    r   r   c                  L    e Zd ZdZ ej
                  d      ZddZddZddZ	y)	r   z# Restore raw html to the document. z^\<\/?([^ >]+)c                ~   t               t        | j                  j                  j                        D ]  }| j                  | j                  j                  j                  |         }| j                  |      r7|dj                  | j                  j                  j                  |            <   || j                  j                  j                  |      <    dfd}rAt        j                  dz  }t        j                  d| d|       }|j                  ||      }n|S ||k(  r|S | j                  |      S )z+ Iterate over html stash and restore html. z	<p>{}</p>c                b    | j                  d      }|vr|dd v rd|dd     dS |S |   S )Nr      <p>z</p>)group)mkeyreplacementss     r   substitute_matchz2RawHtmlPostprocessor.run.<locals>.substitute_matchT   sQ    ''!*C,&q9, ,s1Ry"9 ;4@@J$$r   z([0-9]+)r.   z</p>|r0   zre.Match[str]r#   r"   )r   ranger   	htmlStashhtml_counterstash_to_stringrawHtmlBlocksisblocklevelformatget_placeholderr   HTML_PLACEHOLDERrecompilesubr    )	r   r   ihtmlr3   base_placeholderpatternprocessed_textr2   s	           @r   r    zRawHtmlPostprocessor.runJ   s!   "}tww((556 	FA''(9(9(G(G(JKD  &=A [//GG%%55a8: ;AEL**::1=>	F		% #44{Bjj3(8&:%AQ?S!TUG$[[)94@NKT!!!88N++r   c                    | j                   j                  |      }|rA|j                  d      d   dv ry| j                  j	                  |j                  d            S y)z( Check is block of HTML is block-level. r   r   )!?@%TF)BLOCK_LEVEL_REGEXmatchr/   r   is_block_level)r   rB   r0   s      r   r:   z!RawHtmlPostprocessor.isblocklevelk   sS    ""((.wwqz!} 4477))!''!*55r   c                    t        |      S )z' Convert a stashed object to a string. )r"   r   s     r   r8   z$RawHtmlPostprocessor.stash_to_stringu   s    4yr   Nr!   )rB   r"   r#   bool)
r%   r&   r'   r(   r>   r?   rK   r    r:   r8   r   r   r   r   r   E   s'    -"

#45,Br   r   c                      e Zd ZdZddZy)r   z Restore valid entities c                F    |j                  t        j                  d      }|S )N&)replacer   AMP_SUBSTITUTEr   s     r   r    zAndSubstitutePostprocessor.run}   s    ||D//5r   Nr!   r$   r   r   r   r   r   z   s
    "r   r   zThis class is deprecated and will be removed in the future; use [`UnescapeTreeprocessor`][markdown.treeprocessors.UnescapeTreeprocessor] instead.c                      e Zd ZdZ ej
                  dj                  ej                  ej                              Z
ddZddZy)UnescapePostprocessorz Restore escaped chars. z	{}(\d+){}c                H    t        t        |j                  d                  S )Nr   )chrintr/   )r   r0   s     r   unescapezUnescapePostprocessor.unescape   s    3qwwqz?##r   c                N    | j                   j                  | j                  |      S )N)REr@   rZ   r   s     r   r    zUnescapePostprocessor.run   s    ww{{4==$//r   Nr4   r!   )r%   r&   r'   r(   r>   r?   r;   r   STXETXr\   rZ   r    r   r   r   rV   rV      s6    
 #	L''$((;	<B$0r   rV   )r   r	   r   r   r#   zutil.Registry[Postprocessor])r(   
__future__r   collectionsr   typingr   r    r   r>   markdownr	   r   	Processorr   r   r   
deprecatedrV   r   r   r   <module>rf      s{   ( # # %  	!DNN *2= 2j  \	0M 	0		0r   