o
    „¿Ñg?  ã                   @  sv   d Z ddlmZ ddlmZ ddlmZ ddlm  m	Z ddl
Z
dd	„ ZG d
d„ deƒZG dd„ deƒZdd„ ZdS )z‹
Converts `[[WikiLinks]]` to relative links.

See the [documentation](https://Python-Markdown.github.io/extensions/wikilinks)
for details.
é    )Úannotationsé   )Ú	Extensioné   )ÚInlineProcessorNc                 C  s   t  dd| ¡}d |||¡S )z1 Build a URL from the label, a base, and an end. z([ ]+_)|(_[ ]+)|([ ]+)Ú_z{}{}{})ÚreÚsubÚformat)ÚlabelÚbaseÚendÚclean_label© r   ú]/var/www/html/bloggers_ems/venv/lib/python3.10/site-packages/markdown/extensions/wikilinks.pyÚ	build_url   s   r   c                      s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚWikiLinkExtensionz# Add inline processor to Markdown. c                   s8   ddgddgddgt dgdœ| _	 tƒ jdi |¤Ž d S )	Nú/z%String to append to beginning or URL.zString to append to end of URL.ÚwikilinkzCSS hook. Leave blank for none.z Callable formats URL from label.)Úbase_urlÚend_urlÚ
html_classr   r   )r   ÚconfigÚsuperÚ__init__)ÚselfÚkwargs©Ú	__class__r   r   r   '   s   üzWikiLinkExtension.__init__c                 C  s2   || _ d}t||  ¡ ƒ}||_ |j |dd¡ d S )Nz\[\[([\w0-9_ -]+)\]\]r   éK   )ÚmdÚWikiLinksInlineProcessorÚ
getConfigsÚinlinePatternsÚregister)r   r    ÚWIKILINK_REÚwikilinkPatternr   r   r   ÚextendMarkdown1   s
   z WikiLinkExtension.extendMarkdown)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r'   Ú__classcell__r   r   r   r   r   $   s    
r   c                      s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )r!   z Build link from `wikilink`. c                   s   t ƒ  |¡ || _d S )N)r   r   r   )r   Úpatternr   r   r   r   r   >   s   
z!WikiLinksInlineProcessor.__init__c           	      C  s„   |  d¡ ¡ r5|  ¡ \}}}|  d¡ ¡ }| jd |||ƒ}t d¡}||_| d|¡ |r4| d|¡ nd}|| d¡| 	d¡fS )Nr   r   ÚaÚhrefÚclassÚ r   )
ÚgroupÚstripÚ_getMetar   ÚetreeÚElementÚtextÚsetÚstartr   )	r   ÚmÚdatar   r   r   r   Úurlr.   r   r   r   ÚhandleMatchB   s   
€z$WikiLinksInlineProcessor.handleMatchc                 C  sˆ   | j d }| j d }| j d }t| jdƒr?d| jjv r#| jjd d }d| jjv r1| jjd d }d| jjv r?| jjd d }|||fS )	z$ Return meta data or `config` data. r   r   r   ÚMetaÚwiki_base_urlr   Úwiki_end_urlÚwiki_html_class)r   Úhasattrr    r>   )r   r   r   r   r   r   r   r4   P   s   



z!WikiLinksInlineProcessor._getMeta)r(   r)   r*   r+   r   r=   r4   r,   r   r   r   r   r!   ;   s
    r!   c                  K  s   t di | ¤ŽS )Nr   )r   )r   r   r   r   ÚmakeExtension_   s   rC   )r+   Ú
__future__r   r1   r   Úinlinepatternsr   Úxml.etree.ElementTreer5   ÚElementTreer   r   r   r!   rC   r   r   r   r   Ú<module>   s   $