ó
öÀ„\c           @   sÂ   d  Z  d d l m Z m Z d d l m Z d d l Z d d l m Z e	 r£ d d l
 m Z m Z m Z m Z d d l m Z d d l m Z d d	 l m Z n  d
 „  Z d „  Z d „  Z d S(   sF  
    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.
iÿÿÿÿ(   t   nodest   utils(   t	   iteritemsN(   t   split_explicit_title(   t   Anyt   Dictt   Listt   Tuple(   t   Inliner(   t   Sphinx(   t   RoleFunctionc            s   i  g  ‡  ‡ f d † } | S(   Nc            sÉ   t  j | ƒ } t | ƒ \ } } }	 y ˆ  |	 }
 WnA t t f k
 ru | j j d |  ˆ  f d | ƒˆ  |	 }
 n X| sž ˆ d  k r‘ |
 } qž ˆ |	 } n  t j	 | | d t
 d |
 ƒ} | g g  f S(   Nsc   unable to expand %s extlink with base URL %r, please make sure the base contains '%%s' exactly oncet   linet   internalt   refuri(   R   t   unescapeR   t	   TypeErrort
   ValueErrort   reportert   warningt   NoneR    t	   referencet   False(   t   typt   rawtextt   textt   linenot   inlinert   optionst   contentt   has_explicit_titlet   titlet   partt   full_urlt   pnode(   t   base_urlt   prefix(    s2   lib/python2.7/site-packages/sphinx/ext/extlinks.pyt   role+   s    		(    (   R"   R#   R$   (    (   R"   R#   s2   lib/python2.7/site-packages/sphinx/ext/extlinks.pyt   make_link_role)   s    c         C   sF   x? t  |  j j ƒ D]+ \ } \ } } |  j | t | | ƒ ƒ q Wd  S(   N(   R   t   configt   extlinkst   add_roleR%   (   t   appt   nameR"   R#   (    (    s2   lib/python2.7/site-packages/sphinx/ext/extlinks.pyt   setup_link_rolesA   s    %c         C   s8   |  j  d i  d ƒ |  j d t ƒ i t j d 6t d 6S(   NR'   t   envs   builder-initedt   versiont   parallel_read_safe(   t   add_config_valuet   connectR+   t   sphinxt   __display_version__t   True(   R)   (    (    s2   lib/python2.7/site-packages/sphinx/ext/extlinks.pyt   setupG   s    (   t   __doc__t   docutilsR    R   t   sixR   R1   t   sphinx.util.nodesR   R   t   typingR   R   R   R   t   docutils.parsers.rst.statesR   t   sphinx.applicationR	   t   sphinx.util.typingR
   R%   R+   R4   (    (    (    s2   lib/python2.7/site-packages/sphinx/ext/extlinks.pyt   <module>   s   "		