
    /Vh                        d 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)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      G/home/dcms/DCMS/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   /   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                     d fd j                   j                  j                  r@t        j                  dz  }t        j                  d| d|       j                  |      S |S )z+ Iterate over html stash and restore html. c                   | j                  d      x}rd}n| j                  d      }d}t        |      x}j                  j                  j                  k\  r| j                  d      S j                  j                  j                  j                  |         }|rj                  |      rj                  |      S j                  d| d      S )Nr   T   Fr   <p>z</p>)	groupintr   	htmlStashhtml_counterstash_to_stringrawHtmlBlocksisblocklevelsub)mkeywrappedhtmlpatternr   substitute_matchs       r   r:   z2RawHtmlPostprocessor.run.<locals>.substitute_matchK   s    ggaj s ggaj3xDGG$5$5$B$BBwwqz!''(9(9(G(G(LMDd//5{{#3T::;;/3tfD1ABBr   z([0-9]+)r,   z</p>|r5   zre.Match[str]r"   r!   )r   r/   r0   r   HTML_PLACEHOLDERrecompiler4   )r   r   base_placeholderr9   r:   s   `  @@r   r   zRawHtmlPostprocessor.runI   se    	C 77))#44{Bjj3(8&:%AQ?S!TUG;;/66Kr   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   r8   r5   s      r   r3   z!RawHtmlPostprocessor.isblocklevel_   sS    ""((.wwqz!} 4477))!''!*55r   c                    t        |      S )z' Convert a stashed object to a string. )r!   r   s     r   r1   z$RawHtmlPostprocessor.stash_to_stringi   s    4yr   Nr    )r8   r!   r"   bool)
r$   r%   r&   r'   r=   r>   rE   r   r3   r1   r   r   r   r   r   D   s&    -"

#45,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.runq   s    ||D//5r   Nr    r#   r   r   r   r   r   n   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   )chrr.   r-   )r   r5   s     r   unescapezUnescapePostprocessor.unescape   s    3qwwqz?##r   c                N    | j                   j                  | j                  |      S )N)REr4   rS   r   s     r   r   zUnescapePostprocessor.run   s    ww{{4==$//r   Nr;   r    )r$   r%   r&   r'   r=   r>   formatr   STXETXrU   rS   r   r   r   r   rP   rP   v   s6    
 #	L''$((;	<B$0r   rP   )r   r   r   r   r"   zutil.Registry[Postprocessor])r'   
__future__r   typingr   r    r   r=   markdownr   r   	Processorr   r   r   
deprecatedrP   r   r   r   <module>r_      sx   ( # %  	!DNN *'= 'T  \	0M 	0		0r   