U
    ÿDk\  ã                   @   sŠ   d Z ddlmZ ddlm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.

é    )Úabsolute_import)Úunicode_literals)ÚOrderedDicté   )ÚutilNc                 K   s>   t  ¡ }| t| ƒdd¡ | tƒ dd¡ | tƒ dd¡ |S )z0 Build the default postprocessors for Markdown. Zraw_htmlé   Zamp_substituteé   Úunescapeé
   )r   ZRegistryÚregisterÚRawHtmlPostprocessorÚAndSubstitutePostprocessorÚUnescapePostprocessor)ÚmdÚkwargsZpostprocessors© r   ú9/usr/lib/python3/dist-packages/markdown/postprocessors.pyÚbuild_postprocessors&   s
    r   c                   @   s   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   Úrun:   s    zPostprocessor.runN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   /   s   
r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )r   z# Restore raw html to the document. c                    s°   t ƒ ‰ t| jjjƒD ]H}| jjj| }|  |¡rJ|d ˆ d| jj |¡ < |ˆ | jj |¡< qˆ r’t 	d 
dd„ ˆ D ƒ¡¡}| ‡ fdd„|¡}n|S ||kr¢|S |  |¡S dS )	z+ Iterate over html stash and restore html. Ú
z	<p>%s</p>ú|c                 s   s   | ]}t  |¡V  qd S ©N)ÚreÚescape)Ú.0Úkr   r   r   Ú	<genexpr>S   s     z+RawHtmlPostprocessor.run.<locals>.<genexpr>c                    s   ˆ |   d¡ S )Nr   )Úgroup)Úm©Zreplacementsr   r   Ú<lambda>T   ó    z*RawHtmlPostprocessor.run.<locals>.<lambda>N)r   Úranger   Z	htmlStashZhtml_counterZrawHtmlBlocksÚisblocklevelZget_placeholderr!   ÚcompileÚjoinÚsubr   )r   r   ÚiÚhtmlÚpatternZprocessed_textr   r(   r   r   G   s     
þÿzRawHtmlPostprocessor.runc                 C   s<   t  d|¡}|r8| d¡d dkr&dS | j | d¡¡S dS )Nz^\<\/?([^ >]+)r   r   )ú!ú?ú@ú%TF)r!   Úmatchr&   r   Zis_block_level)r   r1   r'   r   r   r   r,   ]   s    z!RawHtmlPostprocessor.isblocklevelN)r   r   r   r   r   r,   r   r   r   r   r   D   s   r   c                   @   s   e Zd ZdZdd„ ZdS )r   z Restore valid entities c                 C   s   |  tjd¡}|S )Nú&)Úreplacer   ZAMP_SUBSTITUTEr   r   r   r   r   j   s    zAndSubstitutePostprocessor.runNr   r   r   r   r   r   g   s   r   c                   @   s6   e Zd ZdZe dejejf ¡Z	dd„ Z
dd„ ZdS )r   z Restore escaped chars z	%s(\d+)%sc                 C   s   t  t| d¡ƒ¡S )Nr   )r   Zint2strÚintr&   )r   r'   r   r   r   r	   t   s    zUnescapePostprocessor.unescapec                 C   s   | j  | j|¡S r    )ÚREr/   r	   r   r   r   r   r   w   s    zUnescapePostprocessor.runN)r   r   r   r   r!   r-   r   ZSTXZETXr;   r	   r   r   r   r   r   r   o   s   r   )r   Z
__future__r   r   Úcollectionsr   Ú r   r!   r   Z	Processorr   r   r   r   r   r   r   r   Ú<module>   s   	#