a
    6`n                     @   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. 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   run7   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d ZdS )	r
   z# Restore raw html to the document. 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}| vr>|dd  v r:d |dd   dS |S  | S )Nr      <p>z</p>)group)mkeyZreplacementsr   r   substitute_matchN   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   D   s$    

zRawHtmlPostprocessor.runc                 C   s<   t d|}|r8|dd dv r&dS | j|dS dS )Nz^\<\/?([^ >]+)r   r   )!?@%TF)r(   matchr   r   Zis_block_level)r   r,   r    r   r   r   r&   e   s    z!RawHtmlPostprocessor.isblocklevelc                 C   s   t |S )z' Convert a stashed object to a string. )strr   r   r   r   r%   n   s    z$RawHtmlPostprocessor.stash_to_stringN)r   r   r   r   r   r&   r%   r   r   r   r   r
   A   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   v   s    zAndSubstitutePostprocessor.runNr   r   r   r   r   r   s   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)REr*   r   r   r   r   r   r      s    zUnescapePostprocessor.runN)r   r   r   r   r(   r)   r'   r   ZSTXZETXr8   r   r   r   r   r   r   r   {   s   r   )r   collectionsr    r   r(   r   Z	Processorr   r
   r   r   r   r   r   r   <module>   s   	2