o
    ç&•a¿>  ã                   @   sÄ  d Z ddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ ddlmZ ejdkr6dd	lmZ nddlZd
ejkZdejjfdefdefdefdefdœZ	 g d¢ZdZdZed Zed e Ze ed ¡Zed e Z ed e Z!e e!d ¡Z"ed e Z#	 ej$dd�Z%dZ&	 d9dd„Z'e'dƒd d!„ ƒZ(d:d$d%„Z)d&d'„ Z*d9d(d)„Z+d*d+„ Z,	 G d,d-„ d-eƒZ-G d.d/„ d/ƒZ.G d0d1„ d1ƒZ/ed2d3d4gƒZ0G d5d6„ d6ƒZ1d7d8„ Z2esàee3ƒ dS 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).
é    N)Ú
namedtuple©Úwraps)Úcounté   )ÚPep562)é   é
   )Úmetadata)r   é   zxml.etree.ElementTreeÚstrÚchrÚrange)ÚetreeÚstring_typeÚ	text_typeÚint2strÚ	iterrange)8ÚaddressÚarticleÚasideÚ
blockquoteÚdetailsÚdivÚdlÚfieldsetÚ
figcaptionÚfigureÚfooterÚformÚh1Úh2Úh3Úh4Úh5Úh6ÚheaderÚhgroupÚhrÚmainÚmenuÚnavÚolÚpÚpreÚsectionÚtableÚulÚcanvasÚcolgroupÚddÚbodyÚdtÚgroupÚiframeÚliÚlegendÚmathÚmapÚnoscriptÚoutputÚobjectÚoptionÚprogressÚscriptÚstyleÚtbodyÚtdÚtextareaÚtfootÚthÚtheadÚtrÚvideoúúzklzzwxh:z%sz([0-9]+)Úampz
wzxhzdk:%sz
hzzhzkh:%szmarkdown.extensions)r7   ))u   Ö�u   ß¿)u   â´°u   âµ¿é   c                    s   ‡ ‡fdd„}|S )zÔ
    Raise a DeprecationWarning when wrapped function/method is called.

    Usage:
        @deprecated("This method will be removed in version X; use Y instead.")
        def some_method()"
            pass
    c                    s   t ˆ ƒ‡ ‡‡fdd„ƒ}|S )Nc                     s,   t jdˆ j› dˆ› �tˆd� ˆ | i |¤ŽS )Nú'z' is deprecated. ©ÚcategoryÚ
stacklevel)ÚwarningsÚwarnÚ__name__ÚDeprecationWarning)ÚargsÚkwargs)ÚfuncÚmessagerS   © ú//usr/lib/python3/dist-packages/markdown/util.pyÚdeprecated_funcr   s   ýz4deprecated.<locals>.wrapper.<locals>.deprecated_funcr   )rZ   r^   ©r[   rS   )rZ   r]   Úwrapperq   s   zdeprecated.<locals>.wrapperr\   )r[   rS   r`   r\   r_   r]   Ú
deprecatedh   s   	
ra   z&Use 'Markdown.is_block_level' instead.c                 C   s    t | tƒr|  ¡  d¡tv S dS )z+Check if the tag is a block level HTML tag.ú/F)Ú
isinstancer   ÚlowerÚrstripÚBLOCK_LEVEL_ELEMENTS)Útagr\   r\   r]   ÚisBlockLevel~   s   
rh   TFc                 C   sj   t | tƒs|r| du r| S t| ƒS |r|  ¡ dkrdS |  ¡ dv r#dS |  ¡ dv r+dS |r3td|  ƒ‚dS )a  Parses a string representing bool value. If parsing was successful,
       returns True or False. If preserve_none=True, returns True, False,
       or None. If parsing was not successful, raises  ValueError, or, if
       fail_on_errors=False, returns None.NÚnone)ÚtrueÚyesÚyÚonÚ1T)ÚfalseÚnoÚnÚoffÚ0ri   FzCannot parse bool value: %r)rc   r   Úboolrd   Ú
ValueError)ÚvalueÚfail_on_errorsÚpreserve_noner\   r\   r]   ÚparseBoolValue‡   s   
ÿry   c                 C   s@   d| v r
|   dd¡} d| v r|   dd¡} d| v r|   dd¡} | S )zEscape code.ú&z&amp;ú<z&lt;ú>z&gt;)Úreplace)Útextr\   r\   r]   Úcode_escapeš   s   r   c                 C   s.   t  | ¡}t| ƒD ]} |j}|s|   S q	dS )z+Get current stack depth, performantly.
    N)ÚsysÚ	_getframer   Úf_back)ÚsizeÚframer\   r\   r]   Ú_get_stack_depth¥   s   
ÿþr…   c                   C   s   t  ¡ tƒ  dk S )zCReturn true if current stack depth is withing 100 of maximum limit.éd   )r€   Úgetrecursionlimitr…   r\   r\   r\   r]   Únearing_recursion_limit°   s   rˆ   c                   @   s   e Zd ZdZdS )ÚAtomicStringz/A string which should not be further processed.N)rV   Ú
__module__Ú__qualname__Ú__doc__r\   r\   r\   r]   r‰   »   s    r‰   c                   @   s*   e Zd Zddd„Zeedƒdd„ ƒƒZdS )Ú	ProcessorNc                 C   s
   || _ d S ©N©Úmd)Úselfr�   r\   r\   r]   Ú__init__Á   ó   
zProcessor.__init__zUse 'md' instead.c                 C   ó   | j S rŽ   r�   ©r‘   r\   r\   r]   ÚmarkdownÄ   s   zProcessor.markdownrŽ   )rV   rŠ   r‹   r’   Úpropertyra   r–   r\   r\   r\   r]   r�   À   s
    
r�   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )Ú	HtmlStashz{
    This class is used for stashing HTML objects that we extract
    in the beginning and replace with place-holders.
    c                 C   s   d| _ g | _d| _g | _dS )z Create a HtmlStash. r   N)Úhtml_counterÚrawHtmlBlocksÚtag_counterÚtag_datar•   r\   r\   r]   r’   Ñ   s   
zHtmlStash.__init__c                 C   s*   | j  |¡ |  | j¡}|  jd7  _|S )zÿ
        Saves an HTML segment for later reinsertion.  Returns a
        placeholder string that needs to be inserted into the
        document.

        Keyword arguments:

        * html: an html segment

        Returns : a placeholder string

        r   )rš   ÚappendÚget_placeholderr™   )r‘   ÚhtmlÚplaceholderr\   r\   r]   ÚstoreØ   s   zHtmlStash.storec                 C   s   d| _ g | _d S )Nr   )r™   rš   r•   r\   r\   r]   Úresetê   s   
zHtmlStash.resetc                 C   s   t | S rŽ   )ÚHTML_PLACEHOLDER©r‘   Úkeyr\   r\   r]   rž   î   s   zHtmlStash.get_placeholderc                 C   s6   | j  ||||dœ¡ tt| jƒ }|  jd7  _|S )z(Store tag data and return a placeholder.)rg   ÚattrsÚ
left_indexÚright_indexr   )rœ   r�   ÚTAG_PLACEHOLDERr   r›   )r‘   rg   r¦   r§   r¨   r    r\   r\   r]   Ú	store_tagñ   s   
þzHtmlStash.store_tagN)	rV   rŠ   r‹   rŒ   r’   r¡   r¢   rž   rª   r\   r\   r\   r]   r˜   Ë   s    r˜   ÚPriorityItemÚnameÚpriorityc                   @   sz   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zddd„Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚRegistryaô  
    A priority sorted registry.

    A `Registry` instance provides two public methods to alter the data of the
    registry: `register` and `deregister`. Use `register` to add items and
    `deregister` to remove items. See each method for specifics.

    When registering an item, a "name" and a "priority" must be provided. All
    items are automatically sorted by "priority" from highest to lowest. The
    "name" is used to remove ("deregister") and get items.

    A `Registry` instance it like a list (which maintains order) when reading
    data. You may iterate over the items, get an item and get a count (length)
    of all items. You may also check that the registry contains an item.

    When getting an item you may use either the index of the item or the
    string-based "name". For example:

        registry = Registry()
        registry.register(SomeItem(), 'itemname', 20)
        # Get the item by index
        item = registry[0]
        # Get the item by name
        item = registry['itemname']

    When checking that the registry contains an item, you may use either the
    string-based "name", or a reference to the actual item. For example:

        someitem = SomeItem()
        registry.register(someitem, 'itemname', 20)
        # Contains the name
        assert 'itemname' in registry
        # Contains the item instance
        assert someitem in registry

    The method `get_index_for_name` is also available to obtain the index of
    an item using that item's assigned "name".
    c                 C   s   i | _ g | _d| _d S )NF)Ú_dataÚ	_priorityÚ
_is_sortedr•   r\   r\   r]   r’   )  s   
zRegistry.__init__c                 C   s&   t |tƒr|| j ¡ v S || j ¡ v S rŽ   )rc   r   r¯   ÚkeysÚvalues)r‘   Úitemr\   r\   r]   Ú__contains__.  s   
zRegistry.__contains__c                    s    ˆ   ¡  t‡ fdd„ˆ jD ƒƒS )Nc                    s   g | ]	\}}ˆ j | ‘qS r\   )r¯   )Ú.0Úkr-   r•   r\   r]   Ú
<listcomp>7  ó    z%Registry.__iter__.<locals>.<listcomp>)Ú_sortÚiterr°   r•   r\   r•   r]   Ú__iter__5  s   zRegistry.__iter__c                 C   sj   |   ¡  t|tƒr"tƒ }| j| D ]\}}| | j| ||¡ q|S t|tƒr0| j| j| j S | j| S rŽ   )	rº   rc   Úslicer®   r°   Úregisterr¯   Úintr¬   )r‘   r¥   Údatar·   r-   r\   r\   r]   Ú__getitem__9  s   


zRegistry.__getitem__c                 C   s
   t | jƒS rŽ   )Úlenr°   r•   r\   r\   r]   Ú__len__D  r“   zRegistry.__len__c                 C   s   d  | jjt| ƒ¡S )Nz<{}({})>)ÚformatÚ	__class__rV   Úlistr•   r\   r\   r]   Ú__repr__G  s   zRegistry.__repr__c                    s>   ˆ | v r|   ¡  | j ‡ fdd„| jD ƒd ¡S td ˆ ¡ƒ‚)z5
        Return the index of the given name.
        c                    s   g | ]	}|j ˆ kr|‘qS r\   ©r¬   )r¶   ÚxrÈ   r\   r]   r¸   Q  r¹   z/Registry.get_index_for_name.<locals>.<listcomp>r   zNo item named "{}" exists.)rº   r°   Úindexru   rÄ   )r‘   r¬   r\   rÈ   r]   Úget_index_for_nameJ  s   ÿzRegistry.get_index_for_namec                 C   s8   || v r	|   |¡ d| _|| j|< | j t||ƒ¡ dS )aY  
        Add an item to the registry with the given name and priority.

        Parameters:

        * `item`: The item being registered.
        * `name`: A string used to reference the item.
        * `priority`: An integer or float used to sort against all items.

        If an item is registered with a "name" which already exists, the
        existing item is replaced with the new item. Tread carefully as the
        old item is lost with no way to recover it. The new item will be
        sorted according to its priority and will **not** retain the position
        of the old item.
        FN)Ú
deregisterr±   r¯   r°   r�   Ú_PriorityItem)r‘   r´   r¬   r­   r\   r\   r]   r¾   U  s
   

zRegistry.registerTc                 C   s<   z|   |¡}| j|= | j|= W dS  ty   |r‚ Y dS w )za
        Remove an item from the registry.

        Set `strict=False` to fail silently.
        N)rË   r°   r¯   ru   )r‘   r¬   ÚstrictrÊ   r\   r\   r]   rÌ   l  s   
ÿÿzRegistry.deregisterc                 C   s(   | j s| jjdd„ dd� d| _ dS dS )z˜
        Sort the registry by priority from highest to lowest.

        This method is called internally and should never be explicitly called.
        c                 S   r”   rŽ   )r­   )r´   r\   r\   r]   Ú<lambda>�  s    z Registry._sort.<locals>.<lambda>T)r¥   ÚreverseN)r±   r°   Úsortr•   r\   r\   r]   rº   z  s   
þzRegistry._sortc                 C   sp   t |tƒr6tjdtdd� || v r|| j|< dS t| ƒdkr!d}n|  ¡  | jd j	d }|  
|||¡ dS t‚)	zB Register item with priorty 5 less than lowest existing priority. zbUsing setitem to register a processor or pattern is deprecated. Use the `register` method instead.rO   ©rS   Nr   é2   éÿÿÿÿé   )rc   r   rT   rU   rW   r¯   rÂ   rº   r°   r­   r¾   Ú	TypeError)r‘   r¥   rv   r­   r\   r\   r]   Ú__setitem__†  s   
ü
zRegistry.__setitem__c                 C   s4   || v r|   |¡ tjdtdd� dS td |¡ƒ‚)z Deregister an item by name. z^Using del to remove a processor or pattern is deprecated. Use the `deregister` method instead.rO   rÒ   z%Cannot delete key {}, not registered.N)rÌ   rT   rU   rW   ÚKeyErrorrÄ   r¤   r\   r\   r]   Ú__delitem__�  s   

üzRegistry.__delitem__c                 C   s,  t | ƒdkr	d}n||dkr|  ¡  | jd jd }nk|dkr+|  ¡  | jd jd }nZ| d¡s5| d¡r|  |d	d
… ¡}| d¡r[| j| j}|dkrV| j|d	  j}n |d }n| j| j}|t | ƒd	 k rr| j|d	  j}n|d }||| d  }ntd| ƒ‚|  |||¡ tj	dt
dd� d
S )z Register a key by location. r   rÓ   Ú_beginrÕ   Ú_endrÔ   r{   r|   r   Nr	   rO   zFNot a valid location: "%s". Location key must start with a ">" or "<".ziUsing the add method to register a processor or pattern is deprecated. Use the `register` method instead.rÒ   )rÂ   rº   r°   r­   Ú
startswithrË   ru   r¾   rT   rU   rW   )r‘   r¥   rv   Úlocationr­   ÚiÚafterÚbeforer\   r\   r]   Úaddª  s:   

ÿ
üzRegistry.addN)T)rV   rŠ   r‹   rŒ   r’   rµ   r¼   rÁ   rÃ   rÇ   rË   r¾   rÌ   rº   r×   rÙ   rá   r\   r\   r\   r]   r®     s    '
r®   c                 C   sJ   t  | ¡}|rtjd | |d ¡ttrdndd� |d S td t| ¡ƒ‚)zGet attribute.z%'{}' is deprecated. Use '{}' instead.r   r   é   rQ   r   z!module '{}' has no attribute '{}')	Ú__deprecated__ÚgetrT   rU   rÄ   rW   ÚPY37ÚAttributeErrorrV   )r¬   ra   r\   r\   r]   Ú__getattr__Ö  s   

ýrç   )rO   )TF)4rŒ   Úrer€   rT   Úxml.etree.ElementTreeÚxmlÚcollectionsr   Ú	functoolsr   Ú	itertoolsr   Úpep562r   Úversion_infoÚ	importlibr
   Úimportlib_metadatarå   r   ÚElementTreer   r   r   rã   rf   ÚSTXÚETXÚINLINE_PLACEHOLDER_PREFIXÚINLINE_PLACEHOLDERÚcompileÚINLINE_PLACEHOLDER_REÚAMP_SUBSTITUTEr£   ÚHTML_PLACEHOLDER_REr©   Úentry_pointsÚINSTALLED_EXTENSIONSÚRTL_BIDI_RANGESra   rh   ry   r   r…   rˆ   r‰   r�   r˜   rÍ   r®   rç   rV   r\   r\   r\   r]   Ú<module>   sh    


û		



3 Vÿ