U
    d                     @   s|   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
ed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 |S )z0 Build the default postprocessors for Markdown. Zraw_html   Zamp_substitute   )r   ZRegistryregisterRawHtmlPostprocessorAndSubstitutePostprocessor)mdkwargsZpostprocessors r   ;/tmp/pip-unpacked-wheel-muih9_xp/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   run6   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 ]L}| | jjj| }| |rN| d| jj	|< | | jj	|< q fdd} rt
jd }td| d| }|||}n|S ||kr|S | |S dS )z+ Iterate over html stash and restore html. z	<p>{}</p>c                    sF   |  d}| kr>|dd  kr:d |dd   dS |S  | S )Nr      <p>z</p>)group)mkeyreplacementsr   r   substitute_matchO   s    
z2RawHtmlPostprocessor.run.<locals>.substitute_matchz([0-9]+)r   z</p>|N)r   ranger
   Z	htmlStashZhtml_counterstash_to_stringZrawHtmlBlocksisblocklevelformatZget_placeholderr   ZHTML_PLACEHOLDERrecompilesubr   )r   r   ihtmlr!   Zbase_placeholderpatternZprocessed_textr   r   r   r   E   s$    

zRawHtmlPostprocessor.runc                 C   s<   | j |}|r8|dd dkr&dS | j|dS dS )Nr   r   )!?@%TF)BLOCK_LEVEL_REGEXmatchr   r
   Zis_block_level)r   r*   r   r   r   r   r$   f   s    z!RawHtmlPostprocessor.isblocklevelc                 C   s   t |S )z' Convert a stashed object to a string. )strr   r   r   r   r#   o   s    z$RawHtmlPostprocessor.stash_to_stringN)
r   r   r   r   r&   r'   r0   r   r$   r#   r   r   r   r   r   @   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   w   s    zAndSubstitutePostprocessor.runNr   r   r   r   r   r	   t   s   r	   z]This class will be removed in the future; use 'treeprocessors.UnescapeTreeprocessor' instead.c                   @   s6   e Zd ZdZedejej	Z
dd Zdd ZdS )UnescapePostprocessorz Restore escaped chars z	{}(\d+){}c                 C   s   t t|dS )Nr   )chrintr   )r   r   r   r   r   unescape   s    zUnescapePostprocessor.unescapec                 C   s   | j | j|S )N)REr(   r8   r   r   r   r   r      s    zUnescapePostprocessor.runN)r   r   r   r   r&   r'   r%   r   ZSTXZETXr9   r8   r   r   r   r   r   r5   |   s   r5   )r   collectionsr    r   r&   r   Z	Processorr   r   r	   
deprecatedr5   r   r   r   r   <module>   s   4