B
    \
                 @   sP   d Z ddlmZmZ ddlmZ ddlZddlmZ dd Z	dd	 Z
d
d ZdS )aF  
    sphinx.ext.extlinks
    ~~~~~~~~~~~~~~~~~~~

    Extension to save typing and prevent hard-coding of base URLs in the reST
    files.

    This adds a new config value called ``extlinks`` that is created like this::

       extlinks = {'exmpl': ('https://example.invalid/%s.html', prefix), ...}

    Now you can use e.g. :exmpl:`foo` in your documents.  This will create a
    link to ``https://example.invalid/foo.html``.  The link caption depends on
    the *prefix* value given:

    - If it is ``None``, the caption will be the full URL.
    - If it is a string (empty or not), the caption will be the prefix prepended
      to the role content.

    You can also give an explicit caption, e.g. :exmpl:`Foo <foo>`.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    )nodesutils)	iteritemsN)split_explicit_titlec                s   i g f fdd	}|S )Nc          	      s   t |}t|\}}}	y |	 }
W n8 ttfk
r\   |jjd|  f |d  |	 }
Y nX |sxd krp|
}n|	 }tj||d|
d}|gg fS )Nzcunable to expand %s extlink with base URL %r, please make sure the base contains '%%s' exactly once)lineF)ZinternalZrefuri)	r   Zunescaper   	TypeError
ValueErrorZreporterZwarningr   Z	reference)typZrawtexttextlinenoZinlinerZoptionsZcontentZhas_explicit_titletitlepartZfull_urlZpnode)base_urlprefix 2lib/python3.7/site-packages/sphinx/ext/extlinks.pyrole+   s    
zmake_link_role.<locals>.roler   )r   r   r   r   )r   r   r   make_link_role)   s    r   c             C   s4   x.t | jjD ]\}\}}| |t|| qW d S )N)r   ZconfigextlinksZadd_roler   )appnamer   r   r   r   r   setup_link_rolesA   s    r   c             C   s&   |  di d | dt tjddS )Nr   envzbuilder-initedT)versionZparallel_read_safe)Zadd_config_valueZconnectr   sphinxZ__display_version__)r   r   r   r   setupG   s    r   )__doc__Zdocutilsr   r   Zsixr   r   Zsphinx.util.nodesr   r   r   r   r   r   r   r   <module>   s   
