o
    ç&•a¦  ã                   @   sr   d Z ddlmZ ddlmZ ddlZdd„ ZG dd	„ d	ejƒZG d
d„ deƒZ	G dd„ deƒZ
G dd„ deƒZdS )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                 K   s>   t  ¡ }| t| ƒdd¡ | tƒ dd¡ | tƒ dd¡ |S )z0 Build the default postprocessors for Markdown. Úraw_htmlé   Úamp_substituteé   Úunescapeé
   )r   ÚRegistryÚregisterÚRawHtmlPostprocessorÚAndSubstitutePostprocessorÚUnescapePostprocessor)ÚmdÚkwargsÚpostprocessors© r   ú9/usr/lib/python3/dist-packages/markdown/postprocessors.pyÚbuild_postprocessors#   s
   r   c                   @   ó   e Zd ZdZ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 markdown.Postprocessor.

    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   ©ÚselfÚtextr   r   r   Úrun7   s   zPostprocessor.runN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   ,   s    
r   c                   @   s2   e Zd ZdZe d¡Zdd„ Zdd„ Zdd„ Z	d	S )
r   z# Restore raw html to the document. z^\<\/?([^ >]+)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_matchP   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   F   s$   
ÿÿ

zRawHtmlPostprocessor.runc                 C   s<   | j  |¡}|r| d¡d dv rdS | j | d¡¡S dS )Nr   r   )ú!ú?ú@ú%TF)ÚBLOCK_LEVEL_REGEXÚmatchr$   r   Úis_block_level)r   r7   r%   r   r   r   r/   g   s   z!RawHtmlPostprocessor.isblocklevelc                 C   s   t |ƒS )z' Convert a stashed object to a string. )Ústrr   r   r   r   r-   p   s   z$RawHtmlPostprocessor.stash_to_stringN)
r   r   r   r    r3   r4   r?   r   r/   r-   r   r   r   r   r   A   s    
!	r   c                   @   r   )r   z Restore valid entities c                 C   s   |  tjd¡}|S )Nú&)Úreplacer   ÚAMP_SUBSTITUTEr   r   r   r   r   x   s   zAndSubstitutePostprocessor.runNr   r   r   r   r   r   u   s    r   c                   @   s6   e Zd ZdZe d ejej	¡¡Z
dd„ Zdd„ ZdS )r   z Restore escaped chars z	{}(\d+){}c                 C   s   t t| d¡ƒƒS )Nr   )ÚchrÚintr$   )r   r%   r   r   r   r	   ‚   s   zUnescapePostprocessor.unescapec                 C   s   | j  | j|¡S )N)ÚREr5   r	   r   r   r   r   r   …   s   zUnescapePostprocessor.runN)r   r   r   r    r3   r4   r0   r   ÚSTXÚETXrH   r	   r   r   r   r   r   r   }   s
    r   )r    Úcollectionsr   Ú r   r3   r   Ú	Processorr   r   r   r   r   r   r   r   Ú<module>   s    	4