
    -Be                         d Z ddlmZ ddlmZ ddlZ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)a  
Python Markdown

A Python implementation of John Gruber's Markdown.

Documentation: https://python-markdown.github.io/
GitHub: https://github.com/Python-Markdown/markdown/
PyPI: https://pypi.org/project/Markdown/

Started by Manfred Stienstra (http://www.dwerg.net/).
Maintained for a few years by Yuri Takhteyev (http://www.freewisdom.org).
Currently maintained by Waylan Limberg (https://github.com/waylan),
Dmitry Shachnev (https://github.com/mitya57) and Isaac Muse (https://github.com/facelessuser).

Copyright 2007-2018 The Python Markdown Project (v. 1.7 and later)
Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
Copyright 2004 Manfred Stienstra (the original version)

License: BSD (see LICENSE.md for details).

POST-PROCESSORS
=============================================================================

Markdown also allows post-processors, which are similar to preprocessors in
that they need to implement a "run" method. However, they are run after core
processing.

    )OrderedDict   )utilNc                     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      7lib/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 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 markdown.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.run6   s     	r   N__name__
__module____qualname____doc__r   r   r   r   r   r   +   s    r   r   c                   F    e Zd ZdZ ej
                  d      Zd Zd Z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                  |      <    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_matchO   sQ    ''!*C,&q9, ,s1Ry"9 ;4@@J$$r   z([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+   s	           @r   r   zRawHtmlPostprocessor.runE   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)Nr   r   )!?@%TF)BLOCK_LEVEL_REGEXmatchr(   r   is_block_level)r   r:   r)   s      r   r2   z!RawHtmlPostprocessor.isblocklevelf   sS    ""((.wwqz!} 4477))!''!*55r   c                     t        |      S )z' Convert a stashed object to a string. )strr   s     r   r0   z$RawHtmlPostprocessor.stash_to_stringo   s    4yr   N)
r   r   r    r!   r6   r7   rC   r   r2   r0   r   r   r   r   r   @   s'    -"

#45,Br   r   c                       e Zd ZdZd Zy)r   z Restore valid entities c                 F    |j                  t        j                  d      }|S )N&)replacer   AMP_SUBSTITUTEr   s     r   r   zAndSubstitutePostprocessor.runw   s    ||D//5r   Nr   r   r   r   r   r   t   s
    "r   r   z]This class will be removed in the future; use 'treeprocessors.UnescapeTreeprocessor' instead.c                       e Zd ZdZ ej
                  dj                  ej                  ej                              Z
d Zd Zy)UnescapePostprocessorz Restore escaped chars z	{}(\d+){}c                 H    t        t        |j                  d                  S )Nr   )chrintr(   )r   r)   s     r   unescapezUnescapePostprocessor.unescape   s    3qwwqz?##r   c                 N    | j                   j                  | j                  |      S )N)REr8   rR   r   s     r   r   zUnescapePostprocessor.run   s    ww{{4==$//r   N)r   r   r    r!   r6   r7   r3   r   STXETXrT   rR   r   r   r   r   rN   rN   |   s6    
 "	L''$((;	<B$0r   rN   )r!   collectionsr    r   r6   r   	Processorr   r   r   
deprecatedrN   r   r   r   <module>r[      sn   : $  	DNN *1= 1h  :	0M 	0		0r   