U
    \> eä
  ã                   @  sŒ   d Z ddlmZ ddlZddlmZmZ ddlmZ ddl	m
Z
 e
rVddlm  mZ e d¡ZG dd	„ d	eƒZG d
d„ deƒZdd„ ZdS )a<  
An extension to Python Markdown which implements legacy attributes.

Prior to Python-Markdown version 3.0, the Markdown class had an `enable_attributes`
keyword which was on by default and provided for attributes to be defined for elements
using the format `{@key=value}`. This extension is provided as a replacement for
backward compatibility. New documents should be authored using `attr_lists`. However,
numerous documents exist which have been using the old attribute format for many
years. This extension can be used to continue to render those documents correctly.
é    )ÚannotationsN)ÚTreeprocessorÚisString)Ú	Extension)ÚTYPE_CHECKINGz\{@([^\}]*)=([^\}]*)}c                   @  s.   e Zd Zdddœdd„Zddddœdd	„Zd
S )ÚLegacyAttrszetree.ElementÚNone)ÚdocÚreturnc                 C  sz   |  ¡ D ]l}| dd¡}|dk	r4| d|  ||¡¡ |jrTt|jƒrT|  ||j¡|_|jrt|jƒr|  ||j¡|_qdS )z2Find and set values of attributes ({@key=value}). ÚaltN)ÚiterÚgetÚsetÚhandleAttributesÚtextr   Útail)Úselfr	   Úelr   © r   úD/tmp/pip-unpacked-wheel-wj0og6ym/markdown/extensions/legacy_attrs.pyÚrun.   s    zLegacyAttrs.runÚstr)r   Útxtr
   c                   s   ddœ‡ fdd„}t  ||¡S )z5 Set attributes and return text without definitions. zre.Match[str]©Úmatchc                   s$   ˆ   |  d¡|  d¡ dd¡¡ d S )Né   é   Ú
ú )r   ÚgroupÚreplacer   ©r   r   r   ÚattributeCallback;   s    z7LegacyAttrs.handleAttributes.<locals>.attributeCallback)ÚATTR_REÚsub)r   r   r   r"   r   r!   r   r   9   s    zLegacyAttrs.handleAttributesN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   -   s   r   c                   @  s   e Zd Zdd„ ZdS )ÚLegacyAttrExtensionc                 C  s   |j  t|ƒdd¡ dS )z) Add `LegacyAttrs` to Markdown instance. Zlegacyattrsé   N)ZtreeprocessorsÚregisterr   )r   Zmdr   r   r   ÚextendMarkdownA   s    z"LegacyAttrExtension.extendMarkdownN)r%   r&   r'   r+   r   r   r   r   r(   @   s   r(   c                  K  s
   t f | ŽS )N)r(   )Úkwargsr   r   r   ÚmakeExtensionF   s    r-   )Ú__doc__Ú
__future__r   ÚreZmarkdown.treeprocessorsr   r   Zmarkdown.extensionsr   Útypingr   Úxml.etree.ElementTreeÚetreeÚElementTreeÚcompiler#   r   r(   r-   r   r   r   r   Ú<module>   s   
