o
    ç&•aü
  ã                   @   sj   d 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 )a„  
WikiLinks Extension for Python-Markdown
======================================

Converts [[WikiLinks]] to relative links.

See <https://Python-Markdown.github.io/extensions/wikilinks>
for documentation.

Original code Copyright [Waylan Limberg](http://achinghead.com/).

All changes Copyright The Python Markdown Project

License: [BSD](https://opensource.org/licenses/bsd-license.php)

é   )Ú	Extensioné   )ÚInlineProcessoré    Nc                 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   ú?/usr/lib/python3/dist-packages/markdown/extensions/wikilinks.pyÚ	build_url   s   r   c                       s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )ÚWikiLinkExtensionc                    s6   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   ÚextendMarkdown*   s
   z WikiLinkExtension.extendMarkdown)Ú__name__Ú
__module__Ú__qualname__r   r&   Ú__classcell__r   r   r   r   r      s    
r   c                       s,   e Zd Z‡ fdd„Zdd„ Zdd„ Z‡  ZS )r    c                    s   t ƒ  |¡ || _d S )N)r   r   r   )r   Úpatternr   r   r   r   r   5   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   ÚhandleMatch9   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   r2   G   s   



z!WikiLinksInlineProcessor._getMeta)r'   r(   r)   r   r;   r2   r*   r   r   r   r   r    4   s    r    c                  K   s   t di | ¤ŽS )Nr   )r   )r   r   r   r   ÚmakeExtensionV   s   rA   )Ú__doc__r/   r   Úinlinepatternsr   Úxml.etree.ElementTreer3   ÚElementTreer   r   r   r    rA   r   r   r   r   Ú<module>   s    "